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".
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".
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.
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
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;
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.
6 People are following this question.
FlexSim can help you understand and improve any system or process. Transform your existing data into accurate predictions.
FlexSim is a fully 3D simulation software environment. FlexSim can be used to simulate any process in any industry.
FlexSim®, FlexSim Healthcare™, Problem Solved.®, the FlexSim logo, the FlexSim X-mark, and the FlexSim Healthcare logo with stylized Caduceus mark are trademarks of FlexSim Software Products, Inc. All rights reserved.
Privacy | Do not sell or share my personal information | Cookie preferences | Report noncompliance | Terms of use | Legal | © Autodesk Inc. All rights reserved