User Tag List

Results 1 to 6 of 6

Thread: help with comparing string

  1. #1
    Clicker Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)
    alexexhowl's Avatar
    Join Date
    Jan 2015
    Location
    RU, YKT
    Posts
    359
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)

    Question help with comparing string

    comparing "if a text contains only values" possible without edit box?

  2. #2
    Clicker Fusion 2.5 MacFusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleUniversal Windows Platform Export ModuleSWF Export ModuleInstall Creator Pro
    Christian_Wheel's Avatar
    Join Date
    Mar 2010
    Location
    Los Angeles
    Posts
    359
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Sorry, not sure what you mean. Are you trying to determine if a string contains a numeric value?

  3. #3
    Clicker Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)
    alexexhowl's Avatar
    Join Date
    Jan 2015
    Location
    RU, YKT
    Posts
    359
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Christian_Wheel View Post
    Sorry, not sure what you mean. Are you trying to determine if a string contains a numeric value?
    trying to figure how to get if specific string, for example, string object text contains ONLY values = "2019" that will allow me to avoid using edit box object wich is have builtin "if text a string" or if text a value" checking.

  4. #4
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleiOS Export ModuleSWF Export Module
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    Popcorn's Avatar
    Join Date
    Jun 2006
    Location
    Norway, Bergen
    Posts
    2,364
    Mentioned
    13 Post(s)
    Tagged
    0 Thread(s)
    I don't think there are any built-in functions for this. If you compare "A2019" this will return 0, while "20A19" will return 20, so that wouldn't work.
    There are however a couple of ways to deal with it, but none that I find better than just let an invisible edit box do the check.
    The best of those methods would be to use a Fastloop to check if each character in the string is a digit. To do this you will need to run another fastloop to compare it to each of the 10 digits we have.

    It could look something like this:

    - Start Fastloop "Check current character" Number of len(STRING) times

    * On loop "Check current character"
    - Set ISDIGIT off
    - Start Fastloop "digit" 10 times

    * On loop "digit"
    + Compare two general values: Mid(STRING, loopindex("Check current character"),1) equals Mid("0123456789", loopindex("digit"),1)
    - Stop loop ("digit")
    - Set ISDIGIT on

    * On loop "Check current character"
    + Compare Flag: ISDIGIT is off
    -> STRING is not a number
    - Stop loop ("Check current character")


    So basically you check every character in the string and compare it to each of the 10 digits. If the result doesn't return true after the second fastloop is done, it means that that character was not a digit.
    You can also make a variant of this that uses the String search function instead of the second fastloop.

  5. #5
    Clickteam Clickteam
    Simon's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    2,726
    Mentioned
    64 Post(s)
    Tagged
    3 Thread(s)
    Assuming the string, if numeric, will always contain valid float or integer values (0.23.45.67 would not be a valid number for example) you could do:

    compare two general values:
    original_string
    =
    str$(val(original_string))

    This converts the string to a number and back to a string. Any non-numeric characters will be stripped out, or, if it was an invalid string, "0" will be the result. Either way, this would result in a different string to the original and you could say this was numeric (if the above condition was met).

    This only works for integers though, for floating-point numbers you would need a second test. So, if the first test fails, and this second test is true, you will be able to confirm it was a floating point number.

    compare two general values:
    original_string
    =
    str$(val(original_string) * 1.0)

    The *1.0 part ensures that the string->value->string conversion returns a floating point number, even if the original wasn't a float (in this case it will just mean it has .0 ("xxxxxx.0") on the end of the string.

    This is not 100% fool proof, if your text contains exponent symbol ("e") for example, this could potentially be an issue.

  6. #6
    Clicker Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)
    alexexhowl's Avatar
    Join Date
    Jan 2015
    Location
    RU, YKT
    Posts
    359
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    @Popcorn thanks! @Simon thanks! about exponental symbols, it's something like 6,02214129E23 right? and thats happens only if will work with floating point values?

Similar Threads

  1. string comparing
    By felinex in forum Multimedia Fusion 2 - Technical Support
    Replies: 6
    Last Post: 28th April 2018, 03:38 PM
  2. Replies: 1
    Last Post: 4th December 2015, 01:36 AM
  3. Is comparing values faster than comparing strings?
    By Erkabubben in forum Fusion 2.5
    Replies: 9
    Last Post: 13th January 2015, 11:36 AM
  4. Comparing two images
    By Gibbon in forum Multimedia Fusion 2 - Technical Support
    Replies: 8
    Last Post: 14th September 2006, 06:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •