What does "#" mean before a string? [duplicate] - c#

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.

Related

C# Regex replace mutliple backslash(`\`) with single [duplicate]

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

How to delete everything from string after character "/u"? [duplicate]

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:

how to replace double backslash with a single one [duplicate]

This question already has answers here:
Replace "\\" with "\" in a string in C#
(9 answers)
Closed 5 years ago.
I want "PRR\17-18\12" to be PRR\17-18\12
I Have tried below ways but its not working
DepositCode.Replace("\\", "\");
DepositCode.Replace(#"\", #"\");
someone please help
Do you want something like that;
DepositCode= DepositCode.Replace(#"\\", #"\");

C# .Net How to Encode URL space with %20 instead of + [duplicate]

This question already has answers here:
URL Encoding using C#
(14 answers)
Closed 5 years ago.
How to encode query string space with %20 instead of + ?
Because System.Web HttpUtility.UrlEncode() gives the space with +.
https://msdn.microsoft.com/en-us/library/system.uri.escapeuristring(v=vs.110).aspx
var encoded = Uri.EscapeUriString("How to encode");
OUTPUT:
How%20to%20encode

C# string replace for website names [duplicate]

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\"

Categories

Resources