gcue Posted March 17, 2022 Posted March 17, 2022 (edited) Not sure how i can accurately detect if a specific character in a string is a digit. The problem is that that I'm dealing with strings which contain a mix of numbers and alpha characters - so using the Number function is giving me inaccurate results. In the example shown below, C results as a number, again because I'm using the Number function on it. Feel the need to use Number to convert it from a string though. Not sure how to get around this. any recommendations? ;~ $sData = "2123abc3234" $sData = "c2123abc3234" If StringIsDigit(Number(StringLeft($sData, 1))) = 1 Then ConsoleWrite("digit" & @CRLF) EndIf Thanks in advance! Edited March 17, 2022 by gcue
Nine Posted March 17, 2022 Posted March 17, 2022 (edited) You did edit your post, so am I : $sData = "2123abc3234" ;$sData = "c2123abc3234" ;$sData = "abcdedghj" If StringIsDigit(StringLeft($sData, 1)) Then ConsoleWrite("digit" & @CRLF) EndIf Edited March 17, 2022 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Reveal hidden contents Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
gcue Posted March 17, 2022 Author Posted March 17, 2022 i see whats happening.. in the case shown below - it is not considering it is a digit because its looking at c2 not just 2! duh! $sData = "c2123abc3234" If StringIsDigit(StringLeft($sData, 2)) Then ConsoleWrite("digit" & @CRLF) EndIf so using If StringIsDigit(StringTrimLeft(StringLeft($sData, 2),1)) = 1 Then ConsoleWrite("digit" & @CRLF) EndIf thank you!!!
mikell Posted March 18, 2022 Posted March 18, 2022 On 3/17/2022 at 4:44 PM, gcue said: it is not considering it is a digit because its looking at c2 not just 2! Expand according to the title this is simpler If StringRegExp($sData, '^.\d') Then ConsoleWrite("digit" & @CRLF)
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now