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

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:

Related

Replace is not doing the expected replacement [duplicate]

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)

Check if a string only contains the characters > or < or - [duplicate]

This question already has answers here:
.NET Regex Error: [x-y] range in reverse order
(3 answers)
How to match hyphens with Regular Expression?
(6 answers)
Closed 4 years ago.
What I need is to check if a string only contains the characters > or < or -.
So I thought using a RegEx for this, and I found an SO question with the exact same problem, and it has an answer (not the accepted one but the answer with regex)
This is the SO question : String contains only a given set of characters
So I modified the expression in this question to fit my needs like this :
static readonly Regex Validator = new Regex(#"^[><- ]+$");
and I call it like this ;
Validator.IsMatch(testValue)
But it's throwing the error
x-y range in reverse order
There are lots of question on SO about this error but I cant find or understand the answer I need.
So what am I doing wrong with this RegEx?
^[-<>]+$ "-" must come first in C# regex
Escape - within character groups. ([0-9] means "zero to nine" and not "zero, dash or nine")

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(',',' ');

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

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.

Categories

Resources