This question already has answers here:
Why is there an second '\' when I get my path
(2 answers)
Why does .NET add an additional slash to the already existent slashes in a path?
(4 answers)
File name has two backslashes C#
(5 answers)
Closed 3 months ago.
I want to replace all occurences of multiple slash ('') with single backslash
For example
mama\\\\Please\\\\\U0U0001f973\U00.txt
Result should be this
mama\Please\U0U0001f973\U00.txt
I have tried
string file = "mama\\\\Please\\\\\U0U0001f973\U00.txt"
string output = Regex.Replace(file, #"[/\\]{2,}", #"\");
current result
mama\\Please\\\U0U0001f973\U00.txt
Related
This question already has answers here:
How do I write a backslash (\) in a string?
(6 answers)
Closed 8 months ago.
Console.WriteLine("|/ \|");
When I try to write this in the console, it thinks the slashes are escape sequences (that are unknown), and returns the error:
Compilation error (line 22, col 48): Unrecognized escape sequence
Either use raw strings:
Console.WriteLine(#"|/ \|");
Or escape your slash:
Console.WriteLine("|/ \\|");
This question already has answers here:
Removing carriage return and linefeed from the end of a string in C#
(13 answers)
Closed 2 years ago.
Hi i have strange problem. Here is my code:
string tmp = "20_29\u0013";
How can I get rid of that "\u0013"?
Normally I will do it with substring or something but I have some issues with that character ---> \
Could someone help me?
You can use tmp.TrimEnd('\u0013') if it is single char or tmp.Replace("\\u0013", string.Empty) if it is sequence of chars to get "20_29" part:
This question already has answers here:
Quotation mark in string
(3 answers)
C# string replace does not actually replace the value in the string [duplicate]
(3 answers)
Closed 7 years ago.
I have a string that has the value /Daily". and the parameter that i'm trying to pass into my application is /Daily. However after trying a few methods to remove the quote, nothing seems to be working.
Methods used
.remove('"');
.replace("\"");
.trim('"');
Remember that strings in .NET are immutable, so calling the Replace method doesn't actually change the underlying string--it returns a value that represents a new string based on the Replace operation. You'll need to capture that returned value for this to work:
var str = "/Daily\"";
str = str.Replace("\"", "");
Also notice that quotes are escaped by backslashes (\) in C#, rather than forward-slashes.
This question already has answers here:
How do I write a backslash (\) in a string?
(6 answers)
Closed 7 years ago.
I am trying to do a string replace for website names. Here is the code:
string output = input.Replace("C:\Design\Website\", "Someting");
TextBox.Text = osc.output;
The code is incorrect as there is an issue \ with these marks. How can I fix my code?
You need to escape the \:
Either:
"C:\\Design\\Website\\"
Or:
#"C:\Design\Website\"
This question already has answers here:
What's the # in front of a string in C#?
(9 answers)
Closed 8 years ago.
What does "#" mean before a string?
I saw this notation with paths:
string myfolder = #"C:\Users\";
But also with normal strings.
It means it's a literal string, so won't treat \ as an escape character, for example. This page should help you understand it better.