Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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 20-Aug-12 17:23pm
Comments
Wes Aday at 20-Aug-12 22:40pm
   
Why don't you just restrict entry to integers only?
Aniruddh Bhatt at 20-Aug-12 23:20pm
   
my party/customer not agree.
Sergey Alexandrovich Kryukov at 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
Wes Aday at 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 at 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
Rahul Rajat Singh at 21-Aug-12 0:02am
   
Is my solution not working? I have checked it and it seems to be working. Let me know if there is still some problem.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
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)
  Permalink  
Comments
riteshsingh_jsr at 21-Aug-12 0:15am
   
Nice one...
Sergey Alexandrovich Kryukov at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Here is how:
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
  Permalink  
Comments
Rahul Rajat Singh at 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 at 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 at 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 at 21-Aug-12 14:46pm
   
Thank you, Kenneth. :-)
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

How about:
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 Wink | ;)
  Permalink  
v2
Comments
Sergey Alexandrovich Kryukov at 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 at 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 at 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)

  Print Answers RSS
0 Kornfeld Eliyahu Peter 275
1 Maciej Los 204
2 Sergey Alexandrovich Kryukov 200
3 King Fisher 185
4 OriginalGriff 183
0 OriginalGriff 6,223
1 DamithSL 4,724
2 Maciej Los 4,196
3 Kornfeld Eliyahu Peter 3,894
4 Sergey Alexandrovich Kryukov 3,496


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 21 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100