If I have a string consisting of all uppercased letters like: "MY NAME", and I want to convert it to a more readable format like: "My name" or maybe: "My Name" before I insert it to the database.
Yes that's very simple, only it changes 'MY NAME' to 'My name', and he wants the first letter of the second part of the string to capitalize as well . Come on, I know you can do it!!
Hi there.
Yes, that was indeed very simple, but what if I want all starting-letters to become in uppercase like: "My Name" ? That means the first letter in every sentence + the one following a space? Is that just as simple?
No, that's not nearly as simple:)
That involves finding the beginning of each word to capitalize it
You'd want to do something similar to the following:
create variables CurValue, NewValue as text
create variable Indx as integer
create variable Cap as boolean
IF (CurValue = '') THEN EXIT; //just to save a little extra needless processing in case of empty string
Cap := TRUE; //Capitalize the first letter of the sentence regardless
CurValue := LOWERCASE(CurValue); //convert everything to lowercase "in case" we have rogue uppercase letters
FOR Indx := 1 TO STRLEN(CurValue) DO
BEGIN
IF (CurValue[Indx] = ' ') THEN
BEGIN
NewValue += ' '; //by adding a hardcoded space here we avoid having to waste processing on a call to Format()
Cap := TRUE;
END ELSE
BEGIN
IF Cap THEN
BEGIN
NewValue += UPPERCASE(FORMAT(CurValue[Indx]));
Cap := FALSE;
END ELSE
NewValue += FORMAT(CurValue[Indx])
END;
END;
EXIT(NewValue);
I hope this helps
If you are going to use this very often, I'd recommend putting it in a code unit as a method to call.
Using the code above to change all my item descriptions using a processing report.
only a few additions when running it under a report
OnAfterGetRecord()
CLEAR(NewValue); //Added a clear to stop the constant appendg to the string
WholeDescription := LOWERCASE(Item.Description +Item."Description 2")//We use both and combine to make 1
IF (WholeDescription = '') THEN EXIT;
Cap := TRUE;
FOR indx := 1 TO STRLEN(WholeDescription) DO BEGIN
IF (WholeDescription[indx] = ' ') THEN BEGIN
NewValue += ' ';
cap := TRUE;
END ELSE BEGIN
IF cap THEN BEGIN
NewValue += UPPERCASE(FORMAT(WholeDescription[indx]));
cap := FALSE;
END ELSE BEGIN
NewValue += FORMAT(WholeDescription[indx])
END;
END;
END;
Description := (COPYSTR(NewValue,1,30));
"Description 2" := (COPYSTR(NewValue,31,30));
MODIFY;
EXIT;
Comments
if varName is your variable
newval := UPPERCASE(COPYSTR(varName,1,1)) + LOWERCASE(COPYSTR(varName,2));
That will capitalize your first letter and lowercase the rest, simple enough, no?:)
I traded my sanity for a railgun
RIS Plus, LLC
Yes, that was indeed very simple, but what if I want all starting-letters to become in uppercase like: "My Name" ? That means the first letter in every sentence + the one following a space? Is that just as simple?
Thanks
That involves finding the beginning of each word to capitalize it
You'd want to do something similar to the following:
create variables CurValue, NewValue as text
create variable Indx as integer
create variable Cap as boolean
I hope this helps
If you are going to use this very often, I'd recommend putting it in a code unit as a method to call.
I traded my sanity for a railgun
I traded my sanity for a railgun
Nice function. It works just fine.
Thank you very much
I traded my sanity for a railgun
The property only applies if the user manually enters the data. Through code you still have to do the parsing yourself.
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
only a few additions when running it under a report
http://www.BiloBeauty.com
http://www.autismspeaks.org