c# string builder adding " char [duplicate] - c#

This question already has answers here:
Escape double quotes in a string
(9 answers)
Closed 1 year ago.
i want to know how to insert umlaut(") to StringBuilder..
TEXT in HTML :::
<iframe src ="navigation.html" linkTarget = "iframe">
C#
StringBuilder htmlBuilder = new StringBuilder();
htmlBuilder.AppendLine("<iframe src = 'navigation.html' linkTarget = 'iframe'>")
With 'navigation.html' html not working correctly ... i need Append "navigation.html" ,
I want to hear a lot of yours ideas how it could be made ...
Like using chars .. etc.. :)

I think you're just missing the option of using \ to escape the double quote within a string literal:
htmlBuilder.AppendLine("<iframe src=\"navigation.html\" linkTarget=\"iframe\">");

Related

How do I replace a special character [duplicate]

This question already has answers here:
string.Replace (or other string modification) not working
(4 answers)
Closed 12 months ago.
I'm trying to replace a special character "½" with ".5"
cell.InnerText="o208½-105u208½-109o208-110u209-110";
string tempStr=cell.InnerText;
if (cell.InnerText.Contains("½"))
{
cell.InnerText.Replace("½", ".5");
}
string tempStr1 = cell.InnerText;
but my C# .Replace isn't working , I get the same result.
String is an immutable type. Compiler creates a new string after replacing. So try just this
var innerText = "o208½-105u208½-109o208-110u209-110";
innerText= innerText.Replace("½", ".5");
result
before - o208½-105u208½-109o208-110u209-110
after - o208.5-105u208.5-109o208-110u209-110

Replace exact matching string [duplicate]

This question already has answers here:
C# string replace
(9 answers)
Closed 3 years ago.
I want to dynamically replace an exact sub string from a string. For ex I want to replace "dis.[Test Table]" to "dbo.[Test Table]" in the following string:
SELECT Name FROM dis.[Test Table].
Note that I it could be any text and any sub string. It will replace only exactly matched sub string as many times as it will occur.
use String.Replace() Method
fullString = fullString.Replace("oldSubString", "newSubString");
Just to elaborate further, your example can be written as:
var newString = "SELECT Name FROM dis.[Test Table]".Replace("dis.[Test Table]","dbo.[Test Table]");
// newString will become "SELECT Name FROM dbo.[Test Table]"
More details are here

How to remove html tags from text using c# [duplicate]

This question already has answers here:
Remove HTML tags from string including &nbsp in C#
(10 answers)
Closed 8 years ago.
I have the string like
<p>There was a <b>.NET</b> programmer and he stripped the <i>HTML</i> tags.</p><br> </br>
how to remove those html tags from the given string
Use Htmlagilitypack
var document = new HtmlDocument();
document.LoadHtml(data);
string text= document.DocumentNode.InnerText;
you could use Regex.Replace
something like this would do the job
var input = "<p>There was a <b>.NET</b> programmer and he stripped the <i>HTML</i> tags.</p><br> </br>";
var filtered = System.Text.RegularExpressions.Regex.Replace(input, "<.*?>", "");
Console.WriteLine(filtered);

How can i extract a text from string variable using regex? [duplicate]

This question already has answers here:
Regular Expression to Extract the Url out of the Anchor Tag
(3 answers)
Closed 8 years ago.
for (int i = 0; i < lockedThreads.Count; i++)
{
string link = lockedThreads[i];
}
link contains:
<a href="http://rotter.net/cgi-bin/forum/dcboard.cgi?az=read_count&om=111536&forum=scoops1"><b>
I need to get only:
http://rotter.net/cgi-bin/forum/dcboard.cgi?az=read_count&om=111536&forum=scoops1
Each time the link is a different one and each time i need to get the link.
So in the end for example string t
The easy way is
var arr=link.Split('"');
var neededPart=arr[1];
Or You can look here Get string between two strings in a string

Finding the substring [duplicate]

This question already has answers here:
How to get the last five characters of a string using Substring() in C#?
(12 answers)
Closed 9 years ago.
I have a string that could look like this: smithj_Website1 or it could look like this rodgersk_Website5 etc, etc. I want to be able to store in a string what is after the "_". So IE (Website1, Website5,..)
Thanks
Should be a simple as using substring
string mystr = "test_Website1"
string theend = mystr.SubString(mystr.IndexOf("_") + 1)
// theend = "Website1"
mystr.IndexOf("_") will get the position of the _ and adding one to it will get the index of the first character after it. Then don't pass in a second parameter and it will automatically take the substring starting at the character after the _ and stopping and the end of the string.
int startingIndex = inputstring.IndexOf("_") + 1;
string webSite = inputstring.Substring(startingIndex);
or, in one line:
string webSite = inputstring.Substring(inputstring.IndexOf("_") + 1);

Categories

Resources