How to remove characters from string value
-
It may give the appearance of being correct but I don't believe it is what the OP asked for. You are not removing the characters from the string but simply creating an array that excludes them. Now you must recombine the array of characters back into a string to be able to use it.
I know the language. I've read a book. - _Madmatt
yes Mark as Henry pointed me I did big mistake I've not focused my mind on that. now I am realize it was my fault. because of my program OP can only display output after removing character. its not going to remove character from string. its all happen in hurry :(
-
I want to remove , and . From string value but i don't know how to do that. I h've such type of string value string
str ="abc, d.e f,g h,i. J,k"
plz help me
My first answer is only able to display value after removing character it will not remove for permanent. you can us Replace Method to remove . and ,
string str = "abc, d.e f,g h,i. J,k";
str = str.Replace(',',' ');
str = str.Replace('.', ' ');
Console.WriteLine(str); -
Henry Minute wrote:
What do you get when you run that?
yes If I will use your program it will give me Original string but I did programming for removing character and then display it. as i getting OP also what this that's why he greet me for my answer. you are right in your point of view :)
RaviRanjankr wrote:
he greet me for my answer
Yes, and that makes me question his abilities even more.
-
I want to remove , and . From string value but i don't know how to do that. I h've such type of string value string
str ="abc, d.e f,g h,i. J,k"
plz help me
Using the Regex class -
//Getting rid of commas ,
strComma = ",";
strReplace = string.Empty;
Regex Re = new Regex(strComma);
string newstring = Re.Replace(str,strComma,strReplace);
//Do the same for .The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it. My latest tip/trick
modified on Sunday, January 23, 2011 11:29 PM
-
you can simply remove , and . from your string value by using Split function. take a look how to display
string str = "abc, d.e f,g h,i. j,k";
string[] arr = str.Split(',', '.'); // remove all , and .
foreach (string str1 in arr)
{
Console.Write(str1); //output abc de fg hi jk
}modified on Monday, January 24, 2011 1:04 AM
You can do
str = str.Split ( ... ).Join ( ... )
, but it's not the right tool and inefficient. -
Using the Regex class -
//Getting rid of commas ,
strComma = ",";
strReplace = string.Empty;
Regex Re = new Regex(strComma);
string newstring = Re.Replace(str,strComma,strReplace);
//Do the same for .The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it. My latest tip/trick
modified on Sunday, January 23, 2011 11:29 PM
-
Abhinav S wrote:
string.Rmpty;
Now that is funny. :laugh:
I must get a clever new signature for 2011.
string.Rmpty is perfectly acceptable syntax with the Scooby-Do extensions installed. :-D
I know the language. I've read a book. - _Madmatt
-
Abhinav S wrote:
string.Rmpty;
Now that is funny. :laugh:
I must get a clever new signature for 2011.
Is fixed now.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it. My latest tip/trick
-
I want to remove , and . From string value but i don't know how to do that. I h've such type of string value string
str ="abc, d.e f,g h,i. J,k"
plz help me
Try this.
string str = "abc, d.e f,g h,i. J,k";
str = str.Replace(',', string.Empty).Replace('.', string.Empty); -
you can simply remove , and . from your string value by using Split function. take a look how to display
string str = "abc, d.e f,g h,i. j,k";
string[] arr = str.Split(',', '.'); // remove all , and .
foreach (string str1 in arr)
{
Console.Write(str1); //output abc de fg hi jk
}modified on Monday, January 24, 2011 1:04 AM
I have done Minor changes in my answer
string str = "abc, d.e f,g h,i. j,k";
string[] arr = str.Split(',', '.'); // remove all , and .
str = string.Empty; // Changes here
foreach (string str1 in arr)
{
str += str1;
}
Console.WriteLine(str); //output abc de fg hi jk