Jump to content
Sign in to follow this  
zone97

StringReplace Occurance?

Recommended Posts

zone97

Is there a way to do a string replace using occurrence as a replacement based upon location? Lets say I have this text in a string.

;+----------------------------------------------------------+
;¦                                                          ¦
;¦                                                          ¦
;¦                                                          ¦
;¦                                                          ¦
;+----------------------------------------------------------+
;¦                                                          ¦
;+----------------------------------------------------------+
If StringLeft($text, 1) = ";" Then
                $text = StringReplace($text, '+-', '╔═', 1)
                $text = StringReplace($text, '--', '══')
                $text = StringReplace($text, '-+', '═╗', 1)
                $text = StringReplace($text, '¦', '║')
                $text = StringReplace($text, '+-', '╟─', 1)
                $text = StringReplace($text, '--', '──')
                $text = StringReplace($text, '-+', '─╢', 1)
                $text = StringReplace($text, '+-', '╚═', 1)
                $text = StringReplace($text, '--', '══')
                $text = StringReplace($text, '-+', '═╝', 1)
            EndIf

This obviously doesn't work? I have even tried to splitstring at @CR but no luck? Any idea how i could get this done?


 

Spoiler

WinSizer 2.1 (01/04/2017) - Download - [ Windows Layout Manager ]
Folder+Program (12/23/2016) - Download - [ USB Shortcut Creator ]

 

Share this post


Link to post
Share on other sites
mikell
49 minutes ago, zone97 said:

Is there a way to do a string replace using occurrence as a replacement based upon location?

This could be done using StringRegExpReplace, with lookarounds in the pattern to base replacements upon what precedes/follows the string to be replaced

  • Like 1

Share this post


Link to post
Share on other sites
zone97

I made it work with this... But now I want to have it scrub a larger text looking for these to update.

If StringLeft($text, 1) = ";" Then
                $tArray = StringSplit($text, ';')
                $text = ""
                For $x = 1 To $tArray[0] Step 1
                    If $x = 2 Then
                        $tArray[$x] = StringReplace($tArray[$x], '+-', '╔═')
                        $tArray[$x] = StringReplace($tArray[$x], '--', '══')
                        $tArray[$x] = StringReplace($tArray[$x], '-+', '═╗')
                    EndIf
                    If $x > 2 And $x < $tArray[0] Then
                        $tArray[$x] = StringReplace($tArray[$x], '¦', '║')
                        $tArray[$x] = StringReplace($tArray[$x], '+-', '╟─')
                        $tArray[$x] = StringReplace($tArray[$x], '--', '──')
                        $tArray[$x] = StringReplace($tArray[$x], '-+', '─╢')
                    EndIf
                    If $x = $tArray[0] Then
                        $tArray[$x] = StringReplace($tArray[$x], '+-', '╚═')
                        $tArray[$x] = StringReplace($tArray[$x], '--', '══')
                        $tArray[$x] = StringReplace($tArray[$x], '-+', '═╝')
                    EndIf
                    If $x > 1 Then
                        $text = $text & ';' & $tArray[$x]
                    EndIf
                Next
            EndIf

 


 

Spoiler

WinSizer 2.1 (01/04/2017) - Download - [ Windows Layout Manager ]
Folder+Program (12/23/2016) - Download - [ USB Shortcut Creator ]

 

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  

×