Jump to content

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


Zohar
 Share

Recommended Posts

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

Link to comment
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.

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
Link to comment
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
Link to comment
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 :)
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...