|
Henry Minute wrote: That doesn't remove them, it just shows them.
check my code again I have programmed it and then compile and after compilation it gives me output like "abc de fg hi jk".
now what will you say it is removing or showing
|
|
|
|
|
It has not removed them from the original string, they are still there.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
I wouldn't let CG touch my Abacus!
|
|
|
|
|
If it works for me as well as OP then how it isn't work for you. i have again try and it gives me same output
modified on Sunday, January 23, 2011 10:54 PM
|
|
|
|
|
One addition to your code
string str = "abc, d.e f,g h,i. j,k";
string[] arr = str.Split(',', '.');
foreach (string str1 in arr)
{
Console.Write(str1);
}
Console.Write(str);
What do you get when you run that?
The commas and stops are still there. So, once again I say, your code does not remove those characters as the OP asked.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
I wouldn't let CG touch my Abacus!
|
|
|
|
|
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.
|
|
|
|
|
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
|
|
|
|
|
Thanks ravi it works for me.
|
|
|
|
|
you are always welcome
|
|
|
|
|
Although the method will produce the results it is inefficient and causes extra work for you. The String.Replace method is more suitable for the usage you have given.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
You can do str = str.Split ( ... ).Join ( ... ) , but it's not the right tool and inefficient.
|
|
|
|
|
I have done Minor changes in my answer
string str = "abc, d.e f,g h,i. j,k";
string[] arr = str.Split(',', '.');
str = string.Empty;
foreach (string str1 in arr)
{
str += str1;
}
Console.WriteLine(str);
|
|
|
|
|
Simple form :
str.Replace("," , yourValue);
Alternatively you could construct some regex to do the job.
Cheers
If you can read this, you don't have Papyrus installed
|
|
|
|
|
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);
|
|
|
|
|
Using the Regex class -
strComma = ",";
strReplace = string.Empty;
Regex Re = new Regex(strComma);
string newstring = Re.Replace(str,strComma,strReplace);
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.
I must get a clever new signature for 2011.
|
|
|
|
|
string.Rmpty is perfectly acceptable syntax with the Scooby-Do extensions installed.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
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
|
|
|
|
|
Try this.
string str = "abc, d.e f,g h,i. J,k";
str = str.Replace(',', string.Empty).Replace('.', string.Empty);
|
|
|
|
|
I am trying to make a custom open file dialog. So far I managed that it works in VS's UserControl TestContainer. As to the next steps whatv I have to do, I am lost. I have tried to find help in MS docs an on Goolgle but obviously I don't know what to search for, because I found no usefull answers.
So, can someone briefly outline to me the steps which I should take - or better yet - point me to proper point where I can read about it (walkthrough or something like that)?
Regards
|
|
|
|
|
Well I figured a search for "custom open file dialog c#" would be a good start, which yielded this list[^].
I must get a clever new signature for 2011.
|
|
|
|
|
|
Alright, so i got an array like this:
String[] Arr = { "A, B, C", "B, A, C", "C, A", "B, C, A", "D, A, N, V", "N, W, B, A"};
I am trying to extract unique values / remove duplicates from this array, so in the end the output will be like:
A, B, C, D, N, V, W
Now here is my function:
public static String[] Extract(String[] List)
{
String[] Output = null;
String Symbols = String.Empty;
String SymbolsHere = String.Empty;
foreach (String Text in List)
{
if (Text.Contains(","))
{
String[] Vals = Text.Split(new char[] { ',' });
foreach (String Val in Vals)
{
if (SymbolsHere.IndexOf(Val) == -1)
{
SymbolsHere += Val + " ";
Symbols += Val + ", ";
}
}
}
else
{
if (SymbolsHere.IndexOf(Text) == -1)
{
Symbols += Text + ", ";
SymbolsHere += Text + " ";
}
}
}
MessageBox.Show(Symbols);
return Output;
}
Well, this almost works, but...
Last messagebox shows "A, B, C, A, D, N, V, W" instead of "A, B, C, D, N, V, W", so as you can see, one extra "A" char gets into output and i got no idea why
Take a look at this part:
if (SymbolsHere.IndexOf(Val) == -1)
{
MessageBox.Show(SymbolsHere, Val);
SymbolsHere += Val + " ";
Symbols += Val + ", ";
}
So, like, if symbol has not been found in already collected symbols container, show
symbols container itself and a new symbol. But, at this moment app pops a msgbox with collection of syms: A B C and new symbol,
which is not found in our collection: A.
Its like, absurd - A is already there
What is wrong with this code? Thanks
011011010110000101100011011010000110100101101110
0110010101110011
|
|
|
|
|
Not sure what your specs are:
if by symbol you mean a single character, then you are doing it wrong as Split() will return lots of 2-character strings, since your input has spaces. You may want to add a Trim() somewhere.
if by symbol you mean arbitrary multi-character strings ("words"), then IndexOf() is not the right method, as it also reports partial matches (i.e. "Y+" is found in "XY+=").
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|