Sign in to follow this  
Followers 0
Zohar

Is there a Short for Reading and Writing a Char in a String?

7 posts in this topic

Hi

If 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 you

Zohar

Share this post


Link to post
Share on other sites



Maybe StringToASCIIArray?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 by Zohar

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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 :)

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