Click here to Skip to main content
15,905,776 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I want to replace "..-somecharacter-vbLf" with ".-somechracter-vbLf" in whole string. Can any one help???
Posted
Updated 17-Mar-11 19:41pm
v2
Comments
Albin Abel 18-Mar-11 3:02am    
I have posted an improved answer as per your comment. However the any characters part accepts small a-z. You have to try to include caps or other chars
Sergey Alexandrovich Kryukov 20-Mar-11 23:02pm    
Read help before asking Questions like that.
--SA

The String class has the Replace method like testString.Replace("..vblf",".vbLf");.

Similar method is available with StringBuilder class as well. If you are going to do many replacements then better use string builder class

as per your comment

here is the sample with regEx

C#
private void button1_Click(object sender, EventArgs e)
 {
     string input = "bla bla bla ..-anycharacter-vbLf bla bla bla ..-test-vbLf ";
     string pattern = "..-[a-z]*-vbLf";
     string result1 = Regex.Replace(input, pattern, new MatchEvaluator(removeDot));
     MessageBox.Show(result1.ToString());

 }
 private static string removeDot(Match m)
 {
     string x = m.ToString().Replace("..", ".");
     return x;
 }



Extracting the match without the double dot.
 
Share this answer
 
v3
Comments
Abhinav S 18-Mar-11 1:33am    
Good and accurate answer. 5.
Albin Abel 18-Mar-11 1:34am    
Thanks Abhinav
Espen Harlinn 18-Mar-11 5:33am    
Right, my 5
Albin Abel 18-Mar-11 5:49am    
Thanks Espen Harlinn
Sergey Alexandrovich Kryukov 20-Mar-11 23:03pm    
It is good, my 5, but OP does not deserve it.
--SA
This[^] discussion might give you more to think about.
 
Share this answer
 
Comments
Albin Abel 18-Mar-11 1:38am    
Good discussion. 5
Albin Abel 18-Mar-11 1:38am    
Moved OP: comment
Hi, Abhinav S


I want to replace the "..-anycharacter-vbLf" with ".-anycharacter-vbLf".
Sergey Alexandrovich Kryukov 20-Mar-11 23:04pm    
Why do you repeat that? Do you think somebody cannot read? Do your work yourself, use the advices.
--SA
Albin Abel 18-Mar-11 1:40am    
So Riddhi are you familiar with Regular expressions?
Albin Abel 18-Mar-11 1:41am    
Follow up here. http://msdn.microsoft.com/en-us/library/xwewhkd1.aspx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900