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
Related
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
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:
Get Second to last character position from string
(10 answers)
Closed 5 years ago.
* I cannot delete this duplicate question because someone has answered it *
I have file names formatted CustomerInfoDaily.12042014.080043 and CustomerInfoDaily.A.12042014.080043 I'm trying to get the base name (CustomerInfoDaily) and the base suffix (.12042014.080043) using substrings. There is no limit to the number of periods however the suffix is always .\d{8}.\d{8}
string fn = "CustomerInfoDaily.A.12042014.080043";
string baseFileName = fn.Substring(0, fn.LastIndexOf(".",fn.Length-1,fn.Length));
string baseSuffix = fn.Substring(fn.LastIndexOf(".", 0, 2));
The problem is that you can say you want the first or last dot but there is no saying that you want the second to the last instance of the dot.
Any help or advice would be greatly appreciated.
Consider using string.Split:
string fn = "CustomerInfoDaily.A.12042014.080043";
var split = fn.Split('.');
var last = split.LastOrDefault();
var secondLast = split.Skip(split.Length - 2).FirstOrDefault();
This question already has answers here:
How can I check if a string exists in another string
(10 answers)
Closed 5 years ago.
I'm working on a Existing Class file(.cs) which fetches a string with some data in it.
I need to check if the string contains a word. String has no blank spaces in it.
The string-
"<t>StartTxn</t><l>0</l><s>0</s><u>1</u><r>0</r><g>1</g><t>ReleaseUserAuthPending</t>"
I need to check if the string contains 'ReleaseUserAuthPending' in it.
You can try this:
var strValue = "<t>StartTxn</t><l>0</l><s>0</s><u>1</u><r>0</r><g>1</g><t>ReleaseUserAuthPending</t>";
if (strValue.Contains("ReleaseUserAuthPending"))
{
//Do stuff
}
Refer About String - Contains function
For your information: Contains function is case-sensitive. If you want to make this Contains function as case-insensitive. Do the following step from this link.
bool containsString = mystring.Contains("ReleaseUserAuthPending");
Try
String yourString = "<t>StartTxn</t><l>0</l><s>0</s><u>1</u><r>0</r><g>1</g><t>ReleaseUserAuthPending</t>";
if(yourString.Contains("ReleaseUserAuthPending")){
//contains ReleaseUserAuthPending
}else{
//does not contain ReleaseUserAuthPending
}
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);