bafh Posted May 21, 2005 Share Posted May 21, 2005 Hello, I have a string and want to check if it only contains lowercase characters from (ascII) 47-58 and numbers. How would I do that, as short as possible because i dont want to do things like If $var[1] = a then exit If $var[1] = b then exit and so on thanks for answering Link to comment Share on other sites More sharing options...
GaryFrost Posted May 21, 2005 Share Posted May 21, 2005 You mean something like this? $string = 'abcdefghijklmnopqrstuvwxyz0123456789' $test = 'This is a Test' For $x = 1 To StringLen($string) If(StringInStr($test,stringmid($string,$x,1),1)) Then ConsoleWrite("Found: " & stringmid($string,$x,1) & @LF) EndIf Next SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
bafh Posted May 21, 2005 Author Share Posted May 21, 2005 Hmm, no, what i want is to check a string for its characters and only allow characters from a-z and numbers from 0-9, and if the string contains any other characters to make an error. Link to comment Share on other sites More sharing options...
GaryFrost Posted May 21, 2005 Share Posted May 21, 2005 might want to look at the StringIsAlNum function then SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
bafh Posted May 21, 2005 Author Share Posted May 21, 2005 Yes, but there could also be letters,so, if I ceck it for alphanumeric it checks for letters from ascII code 0-125 or something, but i only want 0-9 and a-z Link to comment Share on other sites More sharing options...
GaryFrost Posted May 21, 2005 Share Posted May 21, 2005 also alows for space $string = 'abcdefghijklmnopqrstuvwxyz0123456789 ' $test = 'This is a Test 9' $string_ok = 1 For $x = 1 To StringLen($test) If(StringInStr($string,stringmid($test,$x,1),1) == 0) Then $string_ok = 0 EndIf Next ConsoleWrite($string_ok & @LF) $test = 'this is a test 9' $string_ok = 1 For $x = 1 To StringLen($test) If(StringInStr($string,stringmid($test,$x,1),1) == 0) Then $string_ok = 0 EndIf Next ConsoleWrite($string_ok & @LF) SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
bafh Posted May 21, 2005 Author Share Posted May 21, 2005 That works? i cant test it right now. what if string is "234hsjdfh=)(/"·$" ? Link to comment Share on other sites More sharing options...
GaryFrost Posted May 21, 2005 Share Posted May 21, 2005 (edited) That works?i cant test it right now. what if string is "234hsjdfh=)(/"·$" ?<{POST_SNAPBACK}>Example:$string = 'abcdefghijklmnopqrstuvwxyz0123456789 ' $test = '"234hsjdfh=)(/"·$" ?' $string_ok = 1 For $x = 1 To StringLen($test) If(StringInStr($string,stringmid($test,$x,1),1) == 0) Then $string_ok = 0 ExitLoop EndIf Next If (Not $string_ok) Then ConsoleWrite("String has characters not allowed" & @LF) EndIfoutput>Running: (3.1.1.0):C:\Program Files\AutoIt3\autoit3.exe "C:\Documents and Settings\Gary\My Documents\test5.au3" String has characters not allowed>AutoIT3.exe ended.>Exit code: 0 Time: 1.072Edit: added ExitLoop Edited May 21, 2005 by gafrost SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
kjactive Posted May 21, 2005 Share Posted May 21, 2005 (edited) As I see it there is only a few string manipulation functions build into Autoit and that's StringInStr, StringReplace and StringMid well one could count stringleft/right, Lower/upper and StringLen in but that's all and you has to do with that no matter... kjactive Edited May 21, 2005 by kjactive Au3PP 4.1 - Autoit3 preprocessor, optimize speed, performance to scripts and do executes....[/url]Au3Calibur - Create libraries of commonly used code excerptsWords manipulate UDF, functions that is lent from the rexx language, topics and index file includedCustomDialog UDF to include custom made dialogs like a extended colorpick requester to scripts...[url="ftp://fritidshjemmet.com/Autoit3/SysColor.zip"]SysColor UDF a low level color library to manipulate RGB and Hex values...Shell32 UDF to Automate Windows® operating tasks from native dialog and Wizards browsers... Optimized the CodeWicard with options to generate browser code etc... Link to comment Share on other sites More sharing options...
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