Jump to content

Recommended Posts

Posted (edited)

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
Posted (edited)

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
SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win_10   Build = 19044   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.

Posted

This should work.

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

Saludos

Posted

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 = Win_10   Build = 19044   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.

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
  • Recently Browsing   0 members

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