473,395 Members | 1,869 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Removing numerics(like 2,4,5...) from a string in c#

Can any one please suggest me how to remove numerics in a string of c#
Oct 16 '07 #1
4 1055
Shashi Sadasivan
1,435 Expert 1GB
scan through each character of the string.
if the charachetr is not a numeric copy it to the end of a new string.

Once the above cycle is completed, reference the original string to the new string, and you have your result

cheers
Oct 16 '07 #2
Hi,
Try this code below... first drag and drop a button control in your webform. then copy paste this code below:
ok enjoy!!

private void Button1_Click(object sender, System.EventArgs e)
{
string txtInput = "ABCX123 DEFG111HIGK912";
string txt;
txt = "";
string c;
int P;
string o = "1234567890";
for (int i = 0; i < txtInput.Length ; i++)
{
c = txtInput.Substring(i,1);
P = o.IndexOf(c);
if (P < 0)
{
txt += c;
}
}
Response.Write(txt);
}



regards,
ruel sucgang














Can any one please suggest me how to remove numerics in a string of c#
Oct 16 '07 #3
hi friends at last i found that its easy using regular expressions

steps to reproduce:

1. use 'using system.text.regularexpression' namespace
2. modifiedstring = Regex.Replace(previousstring, "[^0-9]+", "");

Cheers
Naveen
Oct 16 '07 #4
Plater
7,872 Expert 4TB
Hmm what about:
Expand|Select|Wrap|Line Numbers
  1. string demostr="abc45de8ghj";
  2. for(int i=0;i<10;i++)
  3. {
  4.    demostr=demostr.Replace(i.ToString(),"");
  5. }
  6. //now demostr="abcdeghj"
  7.  
Oct 16 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Manzanita | last post by:
Hi. I'm using boost::numerics::ublas to solve linear symmetric and hermitian systems (cholesky, qr, etc.). I'm aware that ublas only provide basic algebra operations (blas1, blas2 and blas3) so...
2
by: rob merritt | last post by:
Hi I have a simple problem hopefully. how would I replace all no numerics using <string name>.regex if if I have a string like 123456.309.123456 or 123456-307-123456 or
6
by: amatuer | last post by:
I usesd this to display info on a page: <% While not rstMain.eof %> <tr> <td><font size="-1"><%= rstMain("Datum") %></font></td> <!-- <td><font size="-1"><b>Client no</b></font></td> -->...
6
by: Niyazi | last post by:
Hi all, What is fastest way removing duplicated value from string array using vb.net? Here is what currently I am doing but the the array contains over 16000 items. And it just do it in 10 or...
17
by: Eric_Dexter | last post by:
def simplecsdtoorc(filename): file = open(filename,"r") alllines = file.read_until("</CsInstruments>") pattern1 = re.compile("</") orcfilename = filename + "orc" for line in alllines: if not...
8
by: Learner | last post by:
Hello, I have a situation that I need to be able to identify if there are any numerical values in a string variable that might have numerics including charecters. For instanse Dim strValue as...
3
by: Goose14 | last post by:
string SelectedSite using (SiteLauncher SiteLaunch = new SiteLauncher() { SiteLaunch.ShowDialog(); SelectedSite = SiteLaunch.SelectedPokerRoom; //this is a property that returns a string } ...
11
by: ramu | last post by:
Hi, Suppose I have a string like this: "I have a string \"and a inner string\\\" I want to remove space in this string but not in the inner string" In the above string I have to remove...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.