Replace is not doing the expected replacement [duplicate] - c#

This question already has answers here:
string.Replace (or other string modification) not working
(4 answers)
Closed last year.
I have a problem in c# with replace in a string with space at the end.
"ERROR.1️.1.1094".Replace("ERROR.1.", "")
Expected value is 1.1094 but it's not working.
Can anybody help me?

Please try the following
"ERROR 1️ 1.1094".Replace("ERROR 1 ", string.Empty)

Related

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(#"\\", #"\");

Remove empty line from string C# [duplicate]

This question already has answers here:
How to remove empty lines from a formatted string
(11 answers)
Closed 6 years ago.
How can I remove empty line from a string for example:
Turn this:
to This:
I used this code text.Replace("\n",""); but it turns it to:
testtesttes
You should replace two newline characters(if any). Following code will work on Unix as well as non unix platforms.
var stringWithoutEmptyLines = yourString.Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine);
string data = stringData.Replace("\r\n\r\n", "\r\n");

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

Remove commas from right side of string in c# [duplicate]

This question already has answers here:
Trim last character from a string
(15 answers)
Closed 8 years ago.
I have string like below.
string s="this is item1,item2,item3,,, ,, ,";
now i want to remove (,) from right side of string.
Thanks in advance
i have tried
string.Replace(",", "");
and
string.TrimEnd("'");
but not working
Try this:
s = s.TrimEnd(',', ' ');
I think the problem in your code is that you do not assign the result of your replacement to any variable. And also your solution would remove all , from the string, not only those on the right side.
Try string.TrimEnd():
s= s.TrimEnd(',',' ');

Categories

Resources