Solved

REPLACE 4

Posted on 2004-10-06
5
227 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 500 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:Desp
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Connecting database in Xamarin? 6 54
Iterate two lists and remove inactive 11 49
Resolve Dependency Issues 4 48
WCF Service Application cannot connect from TCP terminal 1 15
Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

863 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

18 Experts available now in Live!

Get 1:1 Help Now