Jump to content
rootx

[SOLVED] StringReplace Multiple BackSlash help

Recommended Posts

rootx

Hi, I need I trick to remove all double or triple etc... backslash. Thx

$string = "I:\test\\xxx\jjj\\\kkk\k.jpg"

Mmmm, I found a way but if you have more elegant way, please post it!

$string = "I:\test\\xxx\jjj\\\kkk\k.jpg"
$root = StringTrimRight($string,StringLen($string)-3)

$aArray = _StringBetween($string, "\", "\")


For $i = UBound($aArray) - 1 To 0 Step -1
    If $aArray[$i] = "" Then
        _ArrayDelete($aArray, $i)
    EndIf
Next

$string2 = _ArrayToString($aArray,"\")
MsgBox("","",$root&$string2)

 

Edited by rootx

Share this post


Link to post
Share on other sites
Simpel

Hi.

I'm not sure if you really mean remove or mean replace woth only one "\". I guess second. So here is my try with StringRegExpReplace():

Local $string = "I:\test\\xxx\jjj\\\kkk\k.jpg"
$string = StringRegExpReplace($string, "\\+", "\\")
ConsoleWrite($string & @CRLF)

Explanation: searchstring - \\+ - first \ is only masking second\ (otherwise it has another function) and + means one till all \

Replace it with \\. Here the first \ is masking the second \ again.

Conrad

Edited by Simpel
add explanation
  • Like 1

SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win7Pro SP1   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE     H:\...\AutoIt3      H:\...\AutoIt3\Include     (H:\ = Network Drive)

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Share this post


Link to post
Share on other sites
Danyfirex

This should work.

$string = "I:\test\\xxx\jjj\\\kkk\k.jpg"
$string=StringRegExpReplace($string,"\\{2,}","\\")
ConsoleWrite($string & @CRLF)

Saludos

  • Like 1

Share this post


Link to post
Share on other sites
Simpel

Difference between @Danyfirex and mine: My script replaces all existing \, \\, \\\ ... with \ and Danyfirex' starts with minimum 2 \\ - so \\,\\\ ...

Conrad


SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win7Pro SP1   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE     H:\...\AutoIt3      H:\...\AutoIt3\Include     (H:\ = Network Drive)

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

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

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.