question

Durga Ghosal avatar image
2 Likes"
Durga Ghosal asked Ben Wilson edited

Uppercase to Lowercase

How can we convert an uppercase text to lowercase and vice versa. For example, I might have the input text in different format like "TEST" or "TeST" or "TesT", whatever format it is I would like to convert to "TEST" or "test".

FlexSim 16.2.0
string
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Ben Wilson avatar image
1 Like"
Ben Wilson answered Ben Wilson edited

Since FlexSim 2017's introduction of dot syntax, you can convert a string to all upper case or all lower case very easily:

string test = "TesT";
msg(test.toLowerCase(), test.toUpperCase());

See LeGrand Gold's answer for a method that will work with older FlexSim versions.


5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

LeGrand Gold avatar image
5 Likes"
LeGrand Gold answered LeGrand Gold commented

Use this code in a user command:

string input = parstr(1);
string result = "";
int ASCIIoffset = 'a' - 'A';
int curASCII = 0;


for(int i=0; i<=stringlen(input); i++)
{
	curASCII = asciistr(input, i);
	if(curASCII >= 'A' && curASCII < 'a')
		result = concat(result, strascii(curASCII + ASCIIoffset));
	else
		result = concat(result, strascii(curASCII));
}


return result;

A user library with the command as a draggable icon is attached.tolower.fsl


tolower.fsl (534 B)
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

LeGrand Gold avatar image LeGrand Gold commented ·

Updated to do upper case:

string input = param(1);
int upperCase;
parqty() == 2 ? upperCase = param(2) : upperCase = 0;


string result = "";
int ASCIIoffset = 'a' - 'A';
int curASCII = 0;


if(upperCase == 1)
	for(int i=0; i<=stringlen(input); i++)
	{
		curASCII = asciistr(input, i);
		if(curASCII >= 'a' && curASCII <= 'z')
			result = concat(result, strascii(curASCII - ASCIIoffset));
		else
			result = concat(result, strascii(curASCII));
	}
else
	for(int i=0; i<=stringlen(input); i++)
	{
		curASCII = asciistr(input, i);
		if(curASCII >= 'A' && curASCII < 'a')
			result = concat(result, strascii(curASCII + ASCIIoffset));
		else
			result = concat(result, strascii(curASCII));
	}


return result;
1 Like 1 ·
Sam Stubbs avatar image
1 Like"
Sam Stubbs answered

I'm not sure what the application is that you need to change text from lower to upper case. But you could use the stringreplace() command, to search your text and replace any instance of a lower case word with an upper case word.

If however you're trying to compare texts so you want them to be the same, you can actually use the comparetext() command, and use the last parameter to indicate that you want the comparison to ignore case.

You can find details about either of these commands in the command helper.

5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.