Regex remove including start en end char [duplicate] - c#

This question already has answers here:
Regex for string enclosed in <*>, C#
(3 answers)
Closed 2 months ago.
I need to remove the "<www.google.com/>" part from "www.google.com<www.google.com/>"
some regex experts here?
BR
solution from someone

string s = "www.google.com<www.google.com/>";
var result = Regex.Replace(s, "<.*?>", String.Empty);

Related

RegEx...Trying to replace pattern in Html file [duplicate]

This question already has answers here:
Regular expression for floating point numbers
(20 answers)
Closed 3 years ago.
I want to replace the following pattern in an html file
<BR>1696.54</TD>
to
<TD>1696.54</TD>
I am using the RegEx.Replace code
result = Regex.Replace(html, "<BR>\d</TD>", "<TD>$1</TD>")
but I am doing something incorrectly as nothing happens.
Any help would be appreciated..
You need capture a group using parentheses and change :
`\d`
to
`\d*\.\d*`
try this :
result = Regex.Replace(html, "<BR>(\d*\.\d*)</TD>", "<TD>$1</TD>")

How to split string by \ in c# [duplicate]

This question already has answers here:
How do I write a backslash (\) in a string?
(6 answers)
How do I write the escape char '\' to code
(7 answers)
Closed 5 years ago.
I know how to split string. For example.
var str = line.Split(',')[1];
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Müllabfuhr", "Müllabfuhr\Müllabfuhr.csproj", "{1909EBCB-DDDF-469E-9F84-0B0A3B86A861}"
String i used to split.
I want to do the same but now split at "\" . I treid to just insert "\" instead of ",", but i doesnt seem to work.
"C:\Users\lennartf\Desktop\Unbenannt.png"
Try this: var str = #"C:\Users\lennartf\Desktop\Unbenannt.png".Split('\\');

escape for "{" inside C# 6 string interpolation [duplicate]

This question already has answers here:
How to escape braces (curly brackets) in a format string in .NET
(11 answers)
Closed 5 years ago.
I am hoping to use a "{" inside a string interpolation statement but I'm having trouble finding the escape character to do it.
var val = "ERROR_STATE";
var str = $"if(inErrorState){ send 1,\"{val}\" }"
Desired output:
if(inErrorState){send 1,"ERROR_STATE"}
The simple solution is to just not use string interpolation, but I think this way of doing it is easier to read.
Type { twice to escape it:
$"if(inErrorState){{send 1, \"{val}\" }}"
BTW you can do the same with double quotes.

C# Regular Expression - find groups in text with a separator [duplicate]

This question already has an answer here:
Learning Regular Expressions [closed]
(1 answer)
Closed 6 years ago.
I have the following text
"a|mother" "b|father"
I want to find via Regex, groups of text that starts with '"' and ends with '"' and separate with '|' without spaces. Meaning the results would be:
"a|mother"
"b|father"
I try to use other posts to solve my question but still with no luck how can I find the |? and how can I find my pattern without spaces?
Something like this:
String source = "\"a|mother\" \"b|father\"";
var result = Regex
.Matches(source, "\"[^\"]*[^ ]\\|[^ ][^\"]*\"")
.OfType<Match>();
Console.Write(String.Join(Environment.NewLine, result));
Output is
"a|mother"
"b|father"

How to remove accents from Unicode characters? [duplicate]

This question already has answers here:
How do I remove diacritics (accents) from a string in .NET?
(22 answers)
Closed 9 years ago.
I have string with Unicode character, example Hãy đợi đấy.
I need an (ASCII) output Hay doi day.
How can I remove the accents?
You need a library like UnidecodeSharpFork to do that.

Categories