[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

REPLACE 4

Posted on 2004-10-06
5
Medium Priority
?
268 Views
Last Modified: 2010-05-18
Hi Experts,

How can I replace "{" and / or "}" in my string with spaces " " ?
I have tried some things :

Regex.Replace(mystr, @"}", @""); and
my(mystr).Replace('{', ' ');

It does not help.

Thank you.
0
Comment
Question by:fpoyavo
5 Comments
 
LVL 15

Expert Comment

by:praneetha
ID: 12240617
string mystr="hello {fhjsdhfjs";
                  mystr=mystr.Replace(Convert.ToChar(123),Convert.ToChar(32));
                  this.Label1.Text=mystr;


http://www.codetoad.com/ascii_characters_asp.asp
0
 
LVL 8

Expert Comment

by:Razzie_
ID: 12240844
fpoyavo,

string functions do not modify the string itself. If you'd use:

mystr = Regex.Replace(mystr, @"}", @"");

then it would be replaced.
0
 
LVL 9

Accepted Solution

by:
s_sansanwal earned 2000 total points
ID: 12244850
Try

string test = "name{-}microsoft";
test = System.Text.RegularExpressions.Regex.Replace(test, @"[{\}]", " ");


Cheers,
S Sansanwal
0
 
LVL 19

Expert Comment

by:Fahad Mukhtar
ID: 12245646
string s  = "How can I replace { and / or } in my string with spaces   ?";
Console.WriteLine("String before Replace : " + s);
s = s.Replace("{" , " ").Replace("}", " ").Replace("/"," ");
Console.WriteLine("String after Replace : " + s);

and heres the output:
 
String before Replace : How can I replace { and / or } in my string with spaces   ?
String after Replace : How can I replace   and   or   in my string with spaces   ?

Cheers!

Fahad Mukhtar
0
 
LVL 4

Expert Comment

by:Tasneem
ID: 12247899
using System;
using System.Text.RegularExpressions;

string myString;
myString = "This is a test.";
myString = Regex.Replace(myString, " is", " was");
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question