0

I need to compare paths. In a textile, I get paths like:

'C:\\\\Windows\\\\System32\\\\kernel32.dll'

The other path I get from the command line.

To compare the two strings I tried:

while path.find('\\') != -1:
    path.replace('\\\\','\\', 1)

but this changes nothing. Also the builtin functions os.path.normpath() and os.path.realpath() don't remove the backslashes. How to remove the backslashes from the string?

3

4 Answers 4

1

Try:

path = path.replace('\\\\','\\', 1)
Sign up to request clarification or add additional context in comments.

Comments

1

In C# you need to assign the return value from replace. Something like that:

path = path.replace('\\\\','\\', 1)

but I think you are using Java and I don't know if is the same, but try it

1 Comment

This is python, look at the tag. Als while ... : is obviously python.
1

This returns a single backslash and can be compared to output from os.getcwd()

path = path.replace('\\\\', '\\')

Comments

1

to replace 2 \ by one \ , you can do like that:

value = "C:\\\\Windows\\\\System32\\\\kernel32.dll"
print value.replace("\\\\", "\\")

gives me:

C:\Windows\System32\kernel32.dll

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.