Solved

REPLACE 4

Posted on 2004-10-06
5
236 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 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