Zohar Posted February 19, 2013 Share Posted February 19, 2013 HiIf I have a String, and I need to Read and Write Specific Chars in it,(not to insert or delete any chars, but only to Read and or Edit the Existings chars)Is there any Short for it?Right now what I use, is StringMid($String,$i,1), to get the Char in Position i.To Set a char in postion i, it's even longer in terms of writing..In most proghramming language, a string can also be treated as an array of chars,Can it be used similarly in AutoIt too?Thank youZohar Link to comment Share on other sites More sharing options...
johnmcloud Posted February 19, 2013 Share Posted February 19, 2013 Maybe StringToASCIIArray? Link to comment Share on other sites More sharing options...
czardas Posted February 19, 2013 Share Posted February 19, 2013 Perhaps StringRegExpReplace, but I'm not sure if you want global replacements or something different. You haven't mentioned much about the type of editing you want. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Zohar Posted February 19, 2013 Author Share Posted February 19, 2013 (edited) Perhaps StringRegExpReplace, but I'm not sure if you want global replacements or something different. You haven't mentioned much about the type of editing you want.The editting is not according to a spcfici known content,but according to Char position.The only known thing is Char position,that's why I ask If I can treat a String as a Char Array - that way I can edit any char independently.Maybe StringToASCIIArray?Thank you,looks like a nice idea..Also to be used with StringFromASCIIArray() later, to make it a string back again..Thanks! Edited February 19, 2013 by Zohar Link to comment Share on other sites More sharing options...
johnmcloud Posted February 19, 2013 Share Posted February 19, 2013 Thank you,but if the string is Unicode? It won't work well?You can use in alternative StringSplit, if you use "" (an empty string) as the splitter it will split on every character, so does't matter. Link to comment Share on other sites More sharing options...
Malkey Posted February 19, 2013 Share Posted February 19, 2013 Here is an example of using character positions in StringRegExpReplace. Local $sString = "Right now what I use, is StringMid($String,$i,1), to get the Char in Position i." & @CRLF & _ "To Set a char in postion i, it's even longer in terms of writing.." ; 7th, 8th, 9th characters in string is "now" to be replaced with "then". ConsoleWrite( _StringMidReplace($sString, 7, 3, "then") & @LF) Func _StringMidReplace($String, $iStart, $iCount, $sReplacement) Return StringRegExpReplace($sString, "(?s)(.{" & ($iStart - 1) & "})(.{" & $iCount & "})(.*)", "\1" & $sReplacement & "\3") EndFunc ;==>_StringMidReplace Link to comment Share on other sites More sharing options...
Zohar Posted February 19, 2013 Author Share Posted February 19, 2013 You can use in alternative StringSplit, if you use "" (an empty string) as the splitter it will split on every character, so does't matter. Cool. Thank you Here is an example of using character positions in StringRegExpReplace. Return StringRegExpReplace($sString, "(?s)(.{" & ($iStart - 1) & "})(.{" & $iCount & "})(.*)", "\1" & $sReplacement & "\3") Thank you Malkey, but Regular Expressions make it longer here, not shorter like I wished 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