Moderators SmOke_N Posted September 1, 2005 Moderators Share Posted September 1, 2005 I'm trying to insert a hyphen in my string every 3rd letter or number... but every attempt I've tried for the past couple of hours has failed. $RESULT = String("1234567890") $CHANGE[10] $CHANGE[1] = "A" $CHANGE[2] = "B" $CHANGE[3] = "C" $CHANGE[4] = "D" $CHANGE[5] = "E" $CHANGE[6] = "F" $CHANGE[7] = "G" $CHANGE[8] = "H" $CHANGE[9] = "I" $OUT_VAR = "" For $i = 1 to StringLen($RESULT) $a = Number(StringMid($RESULT,$i,1)) $OUT_VAR = $OUT_VAR & $CHANGE[$a] Next This returns the desired result.. But I want to place a Hyphen every 3 places... I could show you the 200 screw ups, but that would be a waist of space. Thanks... Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
pecloe Posted September 1, 2005 Share Posted September 1, 2005 I'm trying to insert a hyphen in my string every 3rd letter or number... but every attempt I've tried for the past couple of hours has failed.$RESULT = String("1234567890") $CHANGE[10] $CHANGE[1] = "A" $CHANGE[2] = "B" $CHANGE[3] = "C" $CHANGE[4] = "D" $CHANGE[5] = "E" $CHANGE[6] = "F" $CHANGE[7] = "G" $CHANGE[8] = "H" $CHANGE[9] = "I" $OUT_VAR = "" For $i = 1 to StringLen($RESULT) $a = Number(StringMid($RESULT,$i,1)) $OUT_VAR = $OUT_VAR & $CHANGE[$a] NextThis returns the desired result.. But I want to place a Hyphen every 3 places... I could show you the 200 screw ups, but that would be a waist of space.Thanks...<{POST_SNAPBACK}>Hey RonI'm a new newbie so forgive the question. I'm missing something but where is the hyphen coming from?Have a great dayPhil Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 1, 2005 Author Moderators Share Posted September 1, 2005 (edited) Not comming from anywhere yet: $RESULT = String("1234567890") Dim $CHANGE[10] $CHANGE[1] = "A" $CHANGE[2] = "B" $CHANGE[3] = "C" $CHANGE[4] = "D" $CHANGE[5] = "E" $CHANGE[6] = "F" $CHANGE[7] = "G" $CHANGE[8] = "H" $CHANGE[9] = "I" $OUT_VAR = "" For $i = 1 to StringLen($RESULT) $a = Number(StringMid($RESULT,$i,1)) $OUT_VAR = $OUT_VAR & $CHANGE[$a] Next $NEW_OUT_VAR = "" For $i = 1 to StringLen($OUT_VAR) Step 3 $a = StringMid($OUT_VAR,$i ,3) $NEW_OUT_VAR = $NEW_OUT_VAR & $a & "-" Next MsgBox(0, "", StringTrimRight($NEW_OUT_VAR, 1)) This did the desired result... guess I just had to "Give In" to get it Edit: Only gave my find... I put it all together. Edit_2: Added Dim, because I'm a DIMWITT!! Edited September 1, 2005 by ronsrules Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
BigDod Posted September 1, 2005 Share Posted September 1, 2005 RonHow come when I run it I gat the following error.D:\AutoIT\test.au3(3,12) : ERROR: syntax error$CHANGE[10]~~~~~~~~~~~^D:\AutoIT\test.au3 - 1 error(s), 0 warning(s)>AU3Check Ended with Error(s).>Running: (3.1.1.68):C:\Program Files\AutoIt3\beta\autoit3.exe "D:\AutoIT\test.au3" D:\AutoIT\test.au3 (3) : ==> Expected a "=" operator in assignment statement.: $CHANGE[10] >AutoIT3.exe ended.>Exit code: 0 Time: 3.626 Time you enjoyed wasting is not wasted time ......T.S. Elliot Suspense is worse than disappointment................Robert Burns God help the man who won't help himself, because no-one else will...........My Grandmother Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 1, 2005 Author Moderators Share Posted September 1, 2005 #include <String.au3> #include <Array.au3> ?? Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
BigDod Posted September 1, 2005 Share Posted September 1, 2005 #include <String.au3>#include <Array.au3>??<{POST_SNAPBACK}>Still the same result but no problem as I am just being nosey and trying to learn from others problems. Time you enjoyed wasting is not wasted time ......T.S. Elliot Suspense is worse than disappointment................Robert Burns God help the man who won't help himself, because no-one else will...........My Grandmother Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 1, 2005 Author Moderators Share Posted September 1, 2005 OMG...!! I'm going to edit the above post... but Dim CHANGE[10] Forgot to add the Dim for ya'll Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Valuater Posted September 1, 2005 Share Posted September 1, 2005 first you need this ( i did)..... Dim $CHANGE[10] second if you do this $RESULT = StringSplit("1234567890") you have your count (number) wtih for/next 8) its early and i don't understand your direction yet Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 1, 2005 Author Moderators Share Posted September 1, 2005 I'm using StringMid in my For/Next... Why would I need to split the string if there isn't a delimeter to be recognized yet? Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Valuater Posted September 1, 2005 Share Posted September 1, 2005 I'm using StringMid in my For/Next... Why would I need to split the string if there isn't a delimeter to be recognized yet?<{POST_SNAPBACK}>$RESULT_2 = StringSplit("1234567890", "") ; string slplit "nothings"and this is the same output alsoFor $i = 1 to StringLen($RESULT)$OUT_VAR = $OUT_VAR & $CHANGE[$i]MsgBox(0,"",$i & " " & $out_var); ;;;;;for testingNext8) Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 1, 2005 Author Moderators Share Posted September 1, 2005 Although I always appreciate your help... I have absolutely no idea what that does... Are you stating that the 2 instances you gave do exactly the same thing?... Thanks Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Valuater Posted September 1, 2005 Share Posted September 1, 2005 how about this $RESULT = StringSplit("1234567890", "") Dim $CHANGE[10] $CHANGE[1] = "A" $CHANGE[2] = "B" $CHANGE[3] = "C" $CHANGE[4] = "D" $CHANGE[5] = "E" $CHANGE[6] = "F" $CHANGE[7] = "G" $CHANGE[8] = "H" $CHANGE[9] = "I" $OUT_VAR = "" For $i = 1 to $RESULT[0]-1 $OUT_VAR = $OUT_VAR & $CHANGE[$i] If StringLen($OUT_VAR) = $RESULT[3] Or StringLen($OUT_VAR) = $RESULT[7] Then $OUT_VAR = $OUT_VAR & "-" EndIf ;MsgBox(0,"",$i & " " & $out_var); for testing Next MsgBox(0,"your desired result",$out_var); for testing Exit 8) Link to comment Share on other sites More sharing options...
Valuater Posted September 1, 2005 Share Posted September 1, 2005 This will do your hyphen with the complete alphabet $text = "" $count = "" For $i = 65 to 90 $count = $count +1 $text = $text & Chr($i) If $count = 3 then $text = $text & "-" $count = "" EndIf Next MsgBox(0, "Uppercase alphabet", $text) not sure if this helps in your direction....I hope it can 8) Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 1, 2005 Author Moderators Share Posted September 1, 2005 That's cool... but what happens if you do this: $Random = Random(1, 9999999999, 1) $RESULT = StringSplit($Random, "") Dim $CHANGE[10] $CHANGE[1] = "A" $CHANGE[2] = "B" $CHANGE[3] = "C" $CHANGE[4] = "D" $CHANGE[5] = "E" $CHANGE[6] = "F" $CHANGE[7] = "G" $CHANGE[8] = "H" $CHANGE[9] = "I" $OUT_VAR = "" For $i = 1 to $RESULT[0]-1 $OUT_VAR = $OUT_VAR & $CHANGE[$i] If StringLen($OUT_VAR) = $RESULT[3] Or StringLen($OUT_VAR) = $RESULT[7] Then $OUT_VAR = $OUT_VAR & "-" EndIf ;MsgBox(0,"",$i & " " & $out_var); for testing Next MsgBox(0,"your desired result",$out_var); for testing Exit It always makes A - I show up in order and the hyphens are in different places ([3] & [7])... and that's not the desired affect if you look at the Number(StringMid()), I'm assigning each digit a Letter value. Now try mine... Remember, I wanted a hyphen every 3 places... $Random = Random(1, 9999999999, 1) $RESULT = String($Random) Dim $CHANGE[10] $CHANGE[1] = "A" $CHANGE[2] = "B" $CHANGE[3] = "C" $CHANGE[4] = "D" $CHANGE[5] = "E" $CHANGE[6] = "F" $CHANGE[7] = "G" $CHANGE[8] = "H" $CHANGE[9] = "I" $OUT_VAR = "" For $i = 1 to StringLen($RESULT) $a = Number(StringMid($RESULT,$i,1)) $OUT_VAR = $OUT_VAR & $CHANGE[$a] Next $NEW_OUT_VAR = "" For $i = 1 to StringLen($OUT_VAR) Step 3 $a = StringMid($OUT_VAR,$i ,3) $NEW_OUT_VAR = $NEW_OUT_VAR & $a & "-" Next MsgBox(0, "", StringTrimRight($NEW_OUT_VAR, 1)) Exit Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 1, 2005 Author Moderators Share Posted September 1, 2005 (edited) This will do your hyphen with the complete alphabet$text = "" $count = "" For $i = 65 to 90 $count = $count +1 $text = $text & Chr($i) If $count = 3 then $text = $text & "-" $count = "" EndIf Next MsgBox(0, "Uppercase alphabet", $text)not sure if this helps in your direction....I hope it can8)<{POST_SNAPBACK}>Yep... looking at this before, would of made my headache go away. But... I still got the desired affect... Your's would make sure the Hyphen wasn't on the end... but then the StringTrimRight does that too.Nice..Edit: Said StringRight / Not StringTrimRight Edited September 1, 2005 by ronsrules Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
w0uter Posted September 1, 2005 Share Posted September 1, 2005 try regexping it evry 3 symbols use a pattern like "(*{3})" and fetch ALL the matches in 1 big array (option 3) then paste the array together with a dash in between each element. just a theory. My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll Link to comment Share on other sites More sharing options...
LxP Posted September 2, 2005 Share Posted September 2, 2005 This is quite an interesting-looking thread but I'm afraid I'm pretty confused. From the very first post it appears that you are trying to do two things in order:Convert certain characters in a string from one to another;Subsequently insert hyphens at every three locations (not overwriting any characters I think).If that's about right, then it would probably be better to accomplish these tasks separately. Link to comment Share on other sites More sharing options...
LxP Posted September 10, 2005 Share Posted September 10, 2005 Perhaps this new UDF will help you achieve what you want? 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