Sign in to follow this  
Followers 0
Realm

[Solved]Detecting a number when it's in a string

3 posts in this topic

#1 ·  Posted (edited)

I found my self confuzzled and cornered. However I'm sure someone here has ran across this lil problem, and may have found or know of a solution.

I'm reading a inifile, then trimming the first character in the string and testing if it is an integer. However I have found that if a number is in string format, that IsInt() will not return it as an integer. same goes for IsNumber()

Example:

Local $aString[3] = ['Test', '2', 3]

For $i = 0 To UBound( $aString ) - 1
   MsgBox('','', IsNumber( $aString[$i])) ;returns only the last one as Int
   MsgBox('','', IsNumber( Int($aString[$i]))) ;returns all three as Int
   MsgBox('','', IsInt( $aString[$i])) ;also returns only the last one as Int
   MsgBox('','', IsInt( Int($aString[$i]))) ;again returns all three as Int
Next

I have attempted to write my own solution

Local $aString[3] = ['N', '2', 3]

For $i = 0 To UBound( $aString ) - 1
   MsgBox('',$aString[$i], _IsStringCharNum($aString[$i]))
Next

Func _IsStringCharNum( $sString )
   If StringLen( $sString ) > 1 Then Return SetError(1)
   For $z = 0 To 9
      If $z = $sString Then Return (1)
   Next
   Return (0)
EndFunc

This does return the stringed '2' as an integer however it counts letters as 0, thus everything is returned as an integer.

Hopefully someone has found a solution to this lil dilemma.

Edit: NVM, While reading over IsInt() in the helpfile for the third time, found the link to StringIsInt() *Embarrased*

Edited by Realm

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites



I always forget about that operator.

Thanks!


My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0