Post Reply 
Padding a string with spaces
03-04-2015, 03:30 AM (This post was last modified: 03-04-2015 03:43 AM by bobkrohn.)
Post: #9
RE: Padding a string with spaces
Just noticed some thing about the "Left Padding".

Appears that the Right Padding fits your String into a block of spaces that you designate.

However, the Left Padding just ADDS these spaces in front of the String.

I was trying to make a "do-all" function and that's why I noticed.
Unless of course I may be doing something wrong.
I'm pretty sure the Centering one is wrong but I quit when I noticed the above discrepancy.
Ideas anyone?
Maybe just subtract the length of your String from the number of desired Left pads?

Code:

EXPORT PadLR(MyStr,MyLen,LorR) 
BEGIN 
  

// True  = -LorR = Left
// False = +LorR = Right
//     0 =       = Left and Right or centered

//  REPLACE("",10+1,"ABCD") = "          ABCD"

//  REPLACE("ABCD",10+1,"") = "ABCD      "


IF LorR < 0 THEN
  REPLACE("",MyLen + 1,MyStr)▶MyStr; 
END;

IF LorR > 0 THEN
  REPLACE(MyStr,MyLen + 1,"")▶MyStr; 
END;

IF LorR == 0 THEN
  REPLACE(MyStr,(MyLen) + 1,"")▶MyStr; 
  REPLACE("",(MyLen/2)+1,MyStr)▶MyStr;
END;

RETURN MyStr;

END;
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Padding a string with spaces - Joe Horn - 03-02-2015, 07:20 AM
RE: Padding a string with spaces - Angus - 03-03-2015, 08:02 AM
RE: Padding a string with spaces - Han - 03-03-2015, 05:08 PM
RE: Padding a string with spaces - bobkrohn - 03-04-2015 03:30 AM
RE: Padding a string with spaces - Angus - 03-04-2015, 05:43 AM



User(s) browsing this thread: 1 Guest(s)