How To Replace Characters In String
Dec 1, 2010i have a string and want to remove text up to the last forward slash, e.g
/images/UserThumbnails/22.jpg
Should now be
22.jpg
How do i go about doing this?
i have a string and want to remove text up to the last forward slash, e.g
/images/UserThumbnails/22.jpg
Should now be
22.jpg
How do i go about doing this?
I need to replace <span> entries in a string to legacy html code because it's going to be used in a report for Crystal Reports. <b> works with Crystal, but the<span>'s do not.
Here's the string which I'm trying to replace: <span style="font-weight: bold">%THIS CAN BE ANY TEXT%</span>. I want to replace it to
<b>%THIS CAN BE ANY TEXT%</b>.
[Code]....
I have to replace XML characters that are being sent to me like this:
Private Balcony & Patios w/Storageto instead be this:
Private Balcony & Patios w/Storage
I want to make sure I have an exhaustive list of all possible characters, so we don't find one later after my programming change.
I was told to do these (by a developer at the client site who is passing me the xml as he gets it from the database and wants me to parse it):
replace all "&" to "&" as well as any of other 3 reserved characters:
">" to "<"
"<" to ">" and
"%" to "%"
But when I googled more infor on XML special characters, I found this list:
& &
< <
> >
" "
' '
Which says nothing about the % but mentions the quote and apostrophe.
So what is the exhaustive list?
I have a string with 100 characters and it is for me too long in one line. I want to make NewLine after each 25 characters. For example:
Instead: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua."
I am trying to write a regular expression to replace all special chracters within a string so that I am left with just alphanumeric characters and spaces or full stops.
I am using this expression at the moment
[Code]....
But then I test this with the string "This is a test!", it returns "Thisis a test", which would be fine, except for the space it removes between "This" and "is", can anyone else me where I am going wrong or supply a better expression?
I want to show just a part of a string for example:
Instead: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua."
Just a: "Lorem ipsum dolor sit amet, consetetur sadipscing..."
Which method can I use to do that?
I want to store into my xml data type column some french characters with accent e.g "é, à , è". The header of my xml file use the encoding style encoding="ISO-8859-1"
My file is the follow :
<?xml version="1.0" encoding="ISO-8859-1"?>
<Magazine DateParution="13-03-2011" Numero="150">
<Title> La chutte du président Osni Mobarack</Title>
<Articles>
<Titre_Article>
Au secours des collèges
</Titre_Article>
<Note_Article>
L'article montre la capitale... </Note_Article>
<Page_Article>1</Page_Article>
</Articles>
</Magazine>
When i store this data into my database using Insert into statement, all the characters with accent are replace by a question mark. for instance get "Au secours des coll?ges"
What can i do in order to SQL Server accept the international characters like french's
I have a string variable contain text that I would like to search for "Keyword" and replace it with new value.
For example:
Dim strValue = " col1 = "John" and col4 = "smith" or col7 <> "closed" or col9 > 1 and col5 = "passed" "
After the replace the strValue should be :
strValue = " col1 = "John" and ( col4 = "smith" or col7 <> "closed" or col9 > 1 ) and col5 = "passed" "
I have a string with special characters insert in different places. For example:
string myString = "This is a textbox: ##";
I would like to replace the ## with a control (namely, a textbox).
The Replace method only allows the string to be replaced with another string or character (understandably). But what would be the best way to dynamically replace the ## with a control in its position?
I was thinking maybe I could replace it with HTML markup which would be executed, but not quite sure how that would be achieved.
EDIT: To clarify some details. The strings are being retrieved from a database, so I can't use the PlaceHolder control. The user selects a string from a drop-down list. The value of the item is the string with special characters. When the postback occurs from the item selection, I would like to display the string on the site, but replace the special characters with a fully working control (in this case, a textbox)
// Build email link
confirmLink = Master.siteDomain + "/newsLetter.aspx?action=confirm&e=" + emailAddress + "&code=" + verCode;
using (SqlCommand cmd = new SqlCommand("SELECT newRegEmailBody, newRegEmailSubj FROM tblSiteSettings WHERE (isActive = 1)", Master.cn))
{
SqlDataReader rdr = cmd.ExecuteReader();
if (rdr.Read())
{
emailBody = rdr[0].ToString();
emailSubj = rdr[1].ToString();
}
rdr.Close();
}
emailBody.Replace("[CONFIRMATION_LINK]", confirmLink);
emailer.sendEmail(emailAddress, Master.noReplyEmail, emailSubj, emailBody);
It all seems to work fine, except the body is still showing up with [CONFIRMATION_LINK] in the text,
how to change
XXX@YYY.ZZZ into XXX_YYY_ZZZ
One way i know is to use the string.replace(char, char) method,
but i want to replace "@" & "." The above method replaces just one char.
one more case is what if i have XX.X@YYY.ZZZ...
i still want the output to look like XX.X_YYY_ZZZ
I am getting taggings like the following in a string
<color> vocation </color>
<color> elation </color>
<color> sage </color>
you can notice that each tagging differs only in the wordings
vocation
elation
sage
But i want to write a code some thing like this
Regex.Replace(userAx, "<color> vocation </color>",
"<color> </color>"
so that the resulting output does not contain words at the centre.In the above code instead of giving the word vocation exclusively, i have to mention some pattern, so that it will replace all the words instead of doing it for first sentence only.How to modify my code?
I am using a chat script I found for free online.
It allows a profanity filter by using string replace:
ex: ChatText.Replace("hell", "!@#$")
is there a way to do a wildcard replace? It doesn't catch the word "HELL" or "Hell" for example.
txtPhoneWork.Text.Replace("-","");
txtPhoneWork.Text.Replace("_", "");
txtMobile.Text.Replace("-", "");
txtMobile.Text.Replace("_", "");
txtPhoneOther.Text.Replace("-", "");
txtPhoneOther.Text.Replace("_", "");
location.ContactWork = txtPhoneWork.Text.Trim();
location.ContactMobile = txtMobile.Text.Trim();
location.ContactOther = txtPhoneOther.Text.Trim();
but it is not replacing and is there any method so that both - and _ can be replaced in single function.
i have convert one of my Repeater to html format using Stringbulider and HtmlTextWriter. now i got html string. my repeater had some image Tags which i don't need it. so i want to replace the image tag(s) with empty sapce. i came to know its possible with using System.Text.RegularExpressions; Regex Thing is dont know how to find the all img tags from the string.
View 2 RepliesSituation: I have a html file and I need to remove certain sections. For Example: The file contains html:
<div style="padding:10px;">First Name:</div><div style="padding:10px; background-color: gray">random information here</div><div style="padding:10px;">First Name:</div><div style="padding:10px; background-color: gray">random information here</div>
I need to remove all text that starts with "<div style="padding:10px; background-color: gray">" and ends with "</div>" so that the result would be:
<div style="padding:10px;">First Name:</div><div style="padding:10px;">First Name:</div>
I created 2 functions that do this, but I do not this it efficient at all. I have a 40mb file and it takes the program about 2 hours to complete. Is there a more efficient way to do this? Is there a way to use regex? See my code below:.....................
((string)dt.Rows[i][1]).Replace("'", "\'")
I want the result that if any string have quote it change it into slash quote, e.g. John's -> John's
but the above replace function is not working fine. it results like John\'s
but if we change the code to
((string)dt.Rows[i][1]).Replace("'", "'")
I have been facing a problam with replace null datetime Field with String.
Like
My DB filed entrydate not mendetory DateTime is dataType.
Its return Entry date or Null.
When designing Crystal report Enrry date display but when it return null its simply display blankspace.
I want like
Enrry date
-----------
07-03-2011
Unavl
12-03-2011
13-03-2011
I have an image control with the following string
[URL]
I want to replace string cleartext=imagePath.Replace("","/"); but the backslash causes a problem -- how can I replace the backslash?
Let's take this string has an example:
D:/firstdir/Another One/and 2/bla bla bla/media/reports/Darth_Vader_Report.pdf
I want to cut the first part of the path:
D:/firstdir/Another One/and 2/bla bla bla
And replace it with **../**, and keep the second part of the path (media/reports/Darth_Vader_Report.pdf)
If I knew the length or size of it, I could use the Replace or Substring. But since the first part of the string is dynamic, how can I do this?
Update
After StriplingWarrior question, I realized that I could have explained better.
The objective is to replace everything behind /media. The "media" directory is static, and will always be the decisive part of the path.
I have a string that I'm pulling from an Excel spreadsheet that is x.firstName
When I pull it in it gets converted to x#FirstName
Fine. So I tried string.replace as shown below and it change my string.
here's my code:
string
stFormattedColumnName = objDataset1.Tables[0].Columns[i].ToString().ToLower();
//value is x#firstName
stFormattedColumnName.Replace('#',
'.');
//value is still x#firstName
I have string. There are no items to show in this view of the "Personal Documents" then assign to string str variable string str ="There are no items to show in this view of the "Personal Documents" library" Now planning to replace "" and make it to actual string to str object. I tried below, but did not worked
str = str.Replace(@"",string.Empty);
I want str value should be string str ="There are no items to show in this view of the "Personal Documents" library" I need to find this string in another string. While searching into that string. I couldn't found because str contains "".
How to replace the remaining String after the Comma Starts Using SQL Query. Below is the data
"MediaRights, MediaRightsLink, MediaRightsCompanies, MediaRightsTypes"
How can I replace the field names in sql query string with variables like:-
string field1="ID";
string field2="Name";
sql = "Insert into [Sheet1$] ('" + field1 + "','" + field2 + "') values('1','abc')";
I am inserting data into an Excel document which has got nearly 100 columns.
I am inserting data using OLEDB as follows:-
System.Data.OleDb.OleDbConnection MyConnection ;
System.Data.OleDb.OleDbCommand myCommand = new System.Data.OleDb.OleDbCommand();
string sql = null;
MyConnection = new System.Data.OleDb.OleDbConnection(connectionstring);
MyConnection.Open();
myCommand.Connection = MyConnection;
sql = "Insert into [Sheet1$] (ID,Name) values('1','abc')";
myCommand.CommandText = sql;
myCommand.ExecuteNonQuery();
MyConnection.Close();
I want to specify the field names at runtime as mentioned above - sql = "Insert into [Sheet1$] ('" + field1 + "','" + field2 + "') values('1','abc')"; When I try this I am getting error.
In my table below string are present which I have to replace *@*$*86$*$ with blank, how can I do? Here bold can be 0-99, in any row.
xOsyH *@*$*86$*$
M. V. *@*$*81$*$ .