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
Related
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\">");
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
This question already has answers here:
C# string replace does not actually replace the value in the string [duplicate]
(3 answers)
Closed 5 years ago.
I have a simple code where I receive data from database:
foreach (DataRow row in tmpDatosModulos.Rows)
{
tmpBSCID += row["ModuloURL"].ToString();
tmpBSCID.Replace("../BSC/wf_BSC_Reporte.aspx?BSCID=", "");
}
Convert.ToInt32(tmpBSCID);
First tmpBSCID receive value like: ../BSC/wf_BSC_Reporte.aspx?BSCID=21 now I want to replace it to drop all this part: ../BSC/wf_BSC_Reporte.aspx?BSCID= and get only last digits after =, but when I debug and it pass Replace instrucion it return all value: ../BSC/wf_BSC_Reporte.aspx?BSCID=21 instead of 21. Why it occurs? Regards
tmpBSCID = tmpBSCID.Replace("../BSC/wf_BSC_Reporte.aspx?BSCID=", "");
Methods on .NET strings do not change the string, they return a new string.
This question already has answers here:
C# string replace does not actually replace the value in the string [duplicate]
(3 answers)
Closed 6 years ago.
I am attempting to replace characters in a string data type. Below is my code, but the ' is not being replaced with ''. Am I mis-understanding how the replace() function operates? What should I do in order to change the string to High Flying Picture''s?
This is the syntax I attempted.
public static void Test()
{
string strVar = "High Flying Picture's";
strVar.Replace("'", "''");
Console.WriteLine(strVar);
}
strVar = strVar.Replace("'", "''");
You need to reassign it.
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