473,387 Members | 1,606 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,387 software developers and data experts.

Search for alpha character - STOP WHEN NUMBER FOUND

G
Hello,

I would like look at a user-entered string, and copy all characters starting
from the left until a number is found. As soon as a number is detected, the
copy should stop and the chracters stored in a second textfield. Sounds
simple but haven't the foggiest how to do it.

For example:

Texfield1.Text = "Bryan2000"
TextField2.Text = "Bryan"

or

TextField1.Text = "H500"
TextField2.text = "H"

or

TextField1.Text = "900TEST"
TextField2.text = ""

Any ideas?

Regards,

G.

Feb 6 '07 #1
3 1464
"G" <g@nospam.comwrote in message
news:7B**********************************@microsof t.com...
Any ideas?
I'm sure there are many cleverer and more efficient ways of doing this,
but...

string strNumbers = "0123456789";
string strText1 = "Bryan2000";
string strText2 = String.Empty;

for (int intPos = 0; intPos < strText1.Length; intPos++)
{
if (strNumbers.Contains(strText1.Substring(intPos, 1)))
{
break;
}
else
{
strText2 += strText1.Substring(intPos, 1);
}
}
Feb 6 '07 #2
G

"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:OP**************@TK2MSFTNGP05.phx.gbl...

You sir, are a genius and a life saver.

G.

Feb 6 '07 #3
Two ways:

public static string GetNonNumericString1(string input)
{
if (String.IsNullOrEmpty(input))
return String.Empty;

System.Text.RegularExpressions.Match match =
System.Text.RegularExpressions.Regex.Match(input, "[^0-9]+");

return match.Success ? match.Value : input;
}

public static string GetNonNumericString2(string input)
{
if (String.IsNullOrEmpty(input))
return String.Empty;

int position = input.IndexOfAny(
new char[] {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'});

return position < 0 ? input : input.Substring(0, position);
}
--
Milosz
"G" wrote:
Hello,

I would like look at a user-entered string, and copy all characters starting
from the left until a number is found. As soon as a number is detected, the
copy should stop and the chracters stored in a second textfield. Sounds
simple but haven't the foggiest how to do it.

For example:

Texfield1.Text = "Bryan2000"
TextField2.Text = "Bryan"

or

TextField1.Text = "H500"
TextField2.text = "H"

or

TextField1.Text = "900TEST"
TextField2.text = ""

Any ideas?

Regards,

G.
Feb 6 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Case Nelson | last post by:
Hi there I've just been playing around with some python code and I've got a fun little optimization problem I could use some help with. Basically, the program needs to take in a random list of no...
7
by: Federico G. Babelis | last post by:
Hi All: I have this line of code, but the syntax check in VB.NET 2003 and also in VB.NET 2005 Beta 2 shows as unknown: Dim local4 As Byte Fixed(local4 = AddressOf dest(offset)) ...
5
by: pembed2003 | last post by:
Hi all, I need to write a function to search and replace part of a char* passed in to the function. I came up with the following: char* search_and_replace(char* source,char search,char*...
1
by: Eric | last post by:
Hi: I have two files. I search pattern ":" from emails text file and save email contents into a database. Another search pattern " field is blank. Please try again.", vbExclamation + vbOKOnly...
1
by: Bill Mill | last post by:
Hello all, What data structure would you use to implement something analogous to the iTunes search? I imagine that it must be a tree of some sort, but I can't figure out an easy structure for...
2
by: Timmy | last post by:
The bigger problem is with the Binary Search. The program crashes when it's excuted. and Visual Studio 2005 indicates stack over flow and shows a break at that function. Sequential search is...
4
by: ravindarjobs | last post by:
hi...... i am using ms access 2003,vb6 i have a form. in that i have 2 buttons 1. start search 2 stop search when i click the "start search" button the fucntion SearchSystem() is called,...
5
by: isabelle | last post by:
hi, every body.. I have two program I couldn’t solve them So, can any body help me. please!! 1-Write a program that accepts a character and count number of occurrences in a file. The file...
14
by: S | last post by:
Any idea on how I would be able to do a search within C# that does ranges or words For example I want to search for Chicken in the string string s1 = "This is Great Chicken";
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.