<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Is there a way to test if a string/char is numeric in FlexSim Forum</title>
    <link>https://forums.autodesk.com/t5/flexsim-forum/is-there-a-way-to-test-if-a-string-char-is-numeric/m-p/13554072#M58055</link>
    <description>&lt;DIV class="fr-view clearfix"&gt;&lt;P&gt;A possibility is to cast the string in question to a Variant. That provides some opportunities for testing the datatype. See &lt;A href="https://docs.flexsim.com/en/22.1/Reference/Tools/UserCommands/UserCommands.html"&gt;Variant Doc&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Example code&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="1661174081057.png"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1512363i848B13FAACF0864B/image-size/large?v=v2&amp;amp;px=999" role="button" title="1661174081057.png" alt="1661174081057.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;/DIV&gt;</description>
    <pubDate>Mon, 22 Aug 2022 13:15:10 GMT</pubDate>
    <dc:creator>lars_jacobsen_ScandiSim</dc:creator>
    <dc:date>2022-08-22T13:15:10Z</dc:date>
    <item>
      <title>Is there a way to test if a string/char is numeric</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/is-there-a-way-to-test-if-a-string-char-is-numeric/m-p/13554071#M58054</link>
      <description>&lt;P&gt;&lt;I&gt;[ FlexSim 22.2.0 ]&lt;/I&gt;&lt;/P&gt;&lt;DIV class="fr-view clearfix"&gt;&lt;P&gt;I have been looking for a way to test if a string or character is a digit or alphanumeric value. In most programming languages there is a function called IsDigit, IsNumeric or something similar, but I cant find that feature in flexscript. &lt;/P&gt;&lt;P&gt;I can use the stringtonum or .tonum methods, but since they always return 0 which is a numeric value rather than NULL, that is rather unhelpfull and a bit of an error in my opinion. You cant tell if the character you converted was actually a 0 or any other character that isnt numeric. &lt;/P&gt;&lt;P&gt;This would be rather usefull when trying to rename autogenerated objects that automatically get a number at the end of their name. I want to find out how many characters the numer at the end of the name is and then replace it with a code of my own choosing.&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 22 Aug 2022 12:32:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/is-there-a-way-to-test-if-a-string-char-is-numeric/m-p/13554071#M58054</guid>
      <dc:creator>MBJEBZSRG</dc:creator>
      <dc:date>2022-08-22T12:32:46Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to test if a string/char is numeric</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/is-there-a-way-to-test-if-a-string-char-is-numeric/m-p/13554072#M58055</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;&lt;P&gt;A possibility is to cast the string in question to a Variant. That provides some opportunities for testing the datatype. See &lt;A href="https://docs.flexsim.com/en/22.1/Reference/Tools/UserCommands/UserCommands.html"&gt;Variant Doc&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Example code&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="1661174081057.png"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1512363i848B13FAACF0864B/image-size/large?v=v2&amp;amp;px=999" role="button" title="1661174081057.png" alt="1661174081057.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 22 Aug 2022 13:15:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/is-there-a-way-to-test-if-a-string-char-is-numeric/m-p/13554072#M58055</guid>
      <dc:creator>lars_jacobsen_ScandiSim</dc:creator>
      <dc:date>2022-08-22T13:15:10Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to test if a string/char is numeric</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/is-there-a-way-to-test-if-a-string-char-is-numeric/m-p/13554073#M58056</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;&lt;P&gt;If the string only consists of ASCII characters, you can check each one by comparing it to the relevant range of ASCII indexes with the &lt;A rel="noopener noreferrer" href="https://docs.flexsim.com/en/22.2/Reference/CodingInFlexSim/FlexScriptAPIReference/Basic/string.html#Operator-bracket" target="_blank"&gt;[] operator&lt;/A&gt;.&lt;/P&gt;&lt;PRE&gt;if(str&lt;I&gt; &amp;gt;= 48 &amp;amp;&amp;amp; test&lt;I&gt; &amp;lt;= 57)
{
&amp;nbsp; &amp;nbsp; // char is numerical
}&lt;/I&gt;&lt;/I&gt;&lt;/PRE&gt;&lt;P&gt;For the purpose of removing/replacing numbers in an autogenerated name, the &lt;A rel="noopener noreferrer" href="https://docs.flexsim.com/en/22.2/Reference/CodingInFlexSim/FlexScriptAPIReference/Basic/string.html#Method-replace" target="_blank"&gt;replace()&lt;/A&gt; method could be useful.&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 22 Aug 2022 14:53:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/is-there-a-way-to-test-if-a-string-char-is-numeric/m-p/13554073#M58056</guid>
      <dc:creator>moehlmann_fe</dc:creator>
      <dc:date>2022-08-22T14:53:37Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to test if a string/char is numeric</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/is-there-a-way-to-test-if-a-string-char-is-numeric/m-p/13554074#M58057</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;&lt;P&gt;If you want to split text from a number, I'd do that with a regex:&lt;/P&gt;&lt;PRE&gt;string name = "Processor23";
var matches = name.match(/(.*[^\d])(\d+)$/);
Array parts;
while ((parts = matches.findNextMatch()).length) {
  print("whole match:", parts[1]);
  print("name:", parts[2]);
  print("number:", parts[3]);
}&lt;/PRE&gt;&lt;P&gt;I often use &lt;A href="https://regex101.com/"&gt;https://regex101.com/&lt;/A&gt; to help me get the regex right.&lt;/P&gt;&lt;P&gt;If you use code like the code above, you can strip off the number from the name part, and then combine the name with some other value.&lt;/P&gt;&lt;P&gt;As far as generally testing a string to see if it is a number, I'd probably use code like this:&lt;/P&gt;&lt;PRE&gt;string test = "123.4";
if (test.match(/^[+-]?([0-9]*[.])?[0-9]+$/).length) {
  return "isNumber";
} else {
  return "not a number";
}&lt;/PRE&gt;&lt;P&gt;You could improve this regex to include scientific notation, if needed.&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 22 Aug 2022 15:55:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/is-there-a-way-to-test-if-a-string-char-is-numeric/m-p/13554074#M58057</guid>
      <dc:creator>JordanLJohnson</dc:creator>
      <dc:date>2022-08-22T15:55:34Z</dc:date>
    </item>
  </channel>
</rss>

