Welcome! Log In Create A New Profile

Advanced

Right justify a fixed character string

Posted by Georgio 
Georgio
Right justify a fixed character string
April 01, 2009 06:21PM
Something tells me this is really easy but I'm trying to figure out
how to justify a fixed character string..

ex.: sMyString is string fixed on 7

If the string only holds 5 chars, I want to push the 5 chars to the right.
Mind you, I know I can do this by substracting the string from the fixed
variable length, adding 1 and then place my place the original char string
starting at the resulting value.

However, this string will be a menu caption and since the font is not a true
type, its not fully pushing over the variable.

Is there a command for this?

Thanks!
Georgio
Georgio
Re: Right justify a fixed character string
April 01, 2009 06:23PM
However, this string will be a menu caption and since the font is not a true
type, its not fully pushing over the variable.


Sorry, it is pushing over the string however it doesn't display neatly. If there
was a right justify option, that be great.

Thanks!
Georgio
Fabrice Harari
Re: Right justify a fixed character string
April 01, 2009 08:10PM
Hi Georgio...

I'm not sure I understand the question, but it may just be that you have to go in the style of the field and select right aligned

best regards

Al
Re: Right justify a fixed character string
April 06, 2009 10:21PM
Hello Georgio

Quote
Georgio
If there was a right justify option, that be great.

I use this proc to right justify strings

PROCEDURE RightJustify(RJFldName="",RJString = " ",RJLength=0)
//RJFldName = field to right justify
//RJString = characters to use in left padding
//RJLength = length of the finished string
//Assume that incoming is NOT Trimmed
LSpace is int = RJLength - Length(NoSpace(RJFldName))
LNewFld is string = ""
IF LSpace > 0
LNewFld = RepeatString(RJString,LSpace) +NoSpace(RJFldName)
ELSE
LNewFld = NoSpace(RJFldName)
END
RESULT LNewFld


Regards
Al
Peter H.
Re: Right justify a fixed character string
April 09, 2009 01:15PM
Hi,

Over time I've built my own StringHandler class that does a lot of stuff on strings that is not covered by PCS. One of these functions is indeed left padding of strings.

Here's the method that covers that:
FUNCTION PadLeft(LOCAL InputString is string, PadCharacter is character, TargetLength is int)
//Do logic
IF TargetLength > Length(InputString) THEN
	//Do logic
	InputString = RepeatString(PadCharacter,TargetLength-Length(InputString)) + InputString
END

//Return padded string
RESULT InputString

Cheers,

P.
Georgio
Re: Right justify a fixed character string
April 09, 2009 06:29PM
Thanks all,

I was making this more complex than it needed to be.

Peter: I'm loving the simplicity of your code!

Thanks!
Georgio
Art Bonds
Re: Right justify a fixed character string
April 09, 2009 08:53PM
Can you clarify this a bit? Are you trying to right justify a menu option? Like in a programs main window, where you have a "&File" on the menu bar, and the drop down menu has "&Configure Printer" and "&Exit", are you trying to right justify the Configure Printer and Exit choices (or their substitute variable)?
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: