Capitalize 1st Char/s
vining
Posts: 4,368
I know there are functions floating around for this but I never seem to find them when I want them and sometimes it's quicker and usually more fun just to write functions from scratch. Since posting my version of functions can sometimes start a healthy debate and I might learn something I otherwise wouldn't have, here are the two functions. I thought of combining them into one and pass in another param to select the output but decided against that for now.
DEFINE_FUNCTION CHAR[MAX_512]fnSet_1stChar_Capital(CHAR iStr[])//changes by reference and return, original can be preserved if line commented out then no change by ref. { STACK_VAR CHAR cStrCopy[MAX_512]; cStrCopy = iStr; if(cStrCopy[1] > 96 && cStrCopy[1] < 123) { cStrCopy[1] = cStrCopy[1]-32; } iStr = cStrCopy;//comment this out to maintain original and then no change by ref RETURN cStrCopy; } DEFINE_FUNCTION CHAR[MAX_8192]fnSetAll_1stChars_Capital(CHAR iStr[])//changes by reference and return, original can be preserved if line commented out then no change by ref. { STACK_VAR CHAR cStrCopy[MAX_8192]; STACK_VAR INTEGER nFBS; cStrCopy = iStr; if(cStrCopy[1] > 96 && cStrCopy[1] < 123) { cStrCopy[1] = cStrCopy[1]-32; } nFBS = find_string(cStrCopy,' ',1); WHILE(nFBS) { if(cStrCopy[nFBS+1] > 96 && cStrCopy[nFBS+1] < 123) { cStrCopy[nFBS+1] = cStrCopy[nFBS+1]-32; } nFBS = find_string(cStrCopy,' ',nFBS+1); } iStr = cStrCopy;//comment this out to maintain original and then no change by ref RETURN cStrCopy; }
0
Comments
First the incoming string goes through ReplaceCRLF() and then StripExtraSpaces() (Shown at the end), then it gets sent to one of the capitalizing routines depending on the type of data.
These functions will force non-leading letters to be lowercase, since they just create a merge of the upper_string() and lower_string() versions of the incoming data.
Paul