Click here to Skip to main content
15,881,089 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi there,

in textbox user will give value like...

27 yrs
40yrs
35 years

so i want remove only characters from textbox , how can i do this?


thanks
Posted
Comments
[no name] 20-Aug-12 22:40pm    
Why don't you just restrict entry to integers only?
Aniruddh Bhatt 20-Aug-12 23:20pm    
my party/customer not agree.
Sergey Alexandrovich Kryukov 21-Aug-12 0:44am    
Who cares? Are you ready to do all your customer tells you, even complete gibberish? And they will say such things, sometimes, to be sure.
--SA
[no name] 21-Aug-12 7:47am    
So maybe you should tell us what you really want to do before anyone wastes more time on this.
Sergey Alexandrovich Kryukov 21-Aug-12 0:44am    
Wes, you probably did not attention how a question is formulated: "remove only characters". As the string contains but characters, is should become string.Empty. This is how I answered it.
--SA

Here is a small code snippet that does the same thing using regex. please modify it as per you project and see if it works.
C#
string s = "27 august";

string pattern = "[a-zA-Z ]*";
string replacement = "";
Regex rgx = new Regex(pattern);
string result = rgx.Replace(s, replacement);
//result = 27 (after this executes)
 
Share this answer
 
Comments
riteshsingh_jsr 21-Aug-12 0:15am    
Nice one...
Sergey Alexandrovich Kryukov 21-Aug-12 0:44am    
You probably did not attention how a question is formulated: "remove only characters". As the string contains but characters, is should become string.Empty. This is how I answered it.
--SA
Here is how:
C#
string RemoveOnlyCharacterFromString(string value) { return string.Empty; }


Explanation: a content of a string is some characters and nothing else. Removing of them, only, should be understood as removing all of the, because there is nothing else.

The question probably based in incorrect understanding of the word "character", which does not make it correct.

Good luck,
—SA
 
Share this answer
 
Comments
Rahul Rajat Singh 21-Aug-12 1:34am    
+5 for taking things literally and sense of humor. (We need such stuff to keep us laughing)
Sergey Alexandrovich Kryukov 21-Aug-12 2:15am    
Agree. I also think that sloppy wording should be corrected, as this is a eternal source of confusion and, hence, waste of time.
Thank you, Rahul.
--SA
Kenneth Haugland 21-Aug-12 14:34pm    
5'ed. For sence of humor and education of the difference between the word charecter and Letter :)
Sergey Alexandrovich Kryukov 21-Aug-12 14:46pm    
Thank you, Kenneth. :-)
--SA
How about:
VB
Private Function ReturnInteger(Byval input as string) as string
   dim output as new system.text.StringBuilder
   
   For each c as char in input
       if not char.IsLetter(c) then
           output.Append(c)
       end if
   next

return output.tosting
end function


http://msdn.microsoft.com/en-us/library/yyxz6h5w.aspx[^]

Its not perfect thoug, if the input is "45 mmm 45" the output would be 4545. But I guess htat would be your problem ;)
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 21-Aug-12 0:44am    
You probably did not attention how a question is formulated: "remove only characters". As the string contains but characters, is should become string.Empty. This is how I answered it.
--SA
Kenneth Haugland 21-Aug-12 0:53am    
:laugh: You are correct, I just assumed he meant Letters not Charecters, due to the vage understanding of english by the questioneer :)
Sergey Alexandrovich Kryukov 21-Aug-12 14:32pm    
No wonder... :-)
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900