Solved

REPLACE 4

Posted on 2004-10-06
5
214 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
Comment Utility
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_
Comment Utility
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 500 total points
Comment Utility
Try

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


Cheers,
S Sansanwal
0
 
LVL 19

Expert Comment

by:Desp
Comment Utility
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
Comment Utility
using System;
using System.Text.RegularExpressions;

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

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now