473,513 Members | 2,881 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

String before the first number

mm
Hi all

I have a string example like this
TSOP65P640X120-20N M 0 0 0 3 9 0 20 1 0

The first number in this case is 6 but it can be between 0 and 9
The first number can be on place between 2 an 6
How do I get the string before the first number (TSOP)

TIA
Mans

Jan 1 '06 #1
6 1453

"mm" <mansj.caiway.nl> wrote in message
news:jo********************************@4ax.com...
Hi all

I have a string example like this
TSOP65P640X120-20N M 0 0 0 3 9 0 20 1 0

The first number in this case is 6 but it can be between 0 and 9
The first number can be on place between 2 an 6
How do I get the string before the first number (TSOP)


^[A-Z]{1,5}

will get the first 1 to 5 upper case letters
Jan 1 '06 #2
split the string using string split, then read the array and convert toInt32
each char. If it doesn't convert, you are at the end of the string and into
the numbers. The just join the bits back together.

--
Regards

John Timney
Microsoft MVP

"mm" <mansj.caiway.nl> wrote in message
news:jo********************************@4ax.com...
Hi all

I have a string example like this
TSOP65P640X120-20N M 0 0 0 3 9 0 20 1 0

The first number in this case is 6 but it can be between 0 and 9
The first number can be on place between 2 an 6
How do I get the string before the first number (TSOP)

TIA
Mans

Jan 1 '06 #3
Hi,
you can use regulare expression for this purpose. try this one :

^(.*?)\d{1}

it will fetch you first match as subMatch. it is more effective than
manualy cheking for a integer in the string.

Jan 2 '06 #4
"John Timney ( MVP )" <ti*****@despammed.com> ha scritto nel messaggio
news:OK*************@tk2msftngp13.phx.gbl...
split the string using string split, then read the array and convert toInt32 each char. If it doesn't convert, you are at the end of the string and into the numbers. The just join the bits back together.


I think you can do better following the split idea: Split the string on
numbers ("0123456789".ToCharArray()) so the stringarray(0) should contain
the string before the first number (of course: you must be sure that the
string doesn't begin with a number!).

--
Free .Net Reporting tool: http://www.neodatatype.net
Jan 2 '06 #5
"mm" <mansj.caiway.nl> wrote in message
news:jo********************************@4ax.com...
Hi all

I have a string example like this
TSOP65P640X120-20N M 0 0 0 3 9 0 20 1 0

The first number in this case is 6 but it can be between 0 and 9
The first number can be on place between 2 an 6
How do I get the string before the first number (TSOP)

TIA
Mans

Since you say the first number's max position is 6, then this won't take
too many resources
This code does not validate or check for string index out of bounds errors,
but may give you an idea of another approach.::::
'------------------------------------------------------------
Private Function getFirstChars(stringIn as String) as String
Dim stringOut as String = ""
Dim n as integer = 0
Do While not IsNumeric(stringIn.Substring( n, 1))
stringOut &= stringIn.Substring(n,1)
n += 1
Loop
Return stringOut
End Function
'-----------------------------------------Use it like this
strMyString = getFirstChars( strBigString)
Jan 3 '06 #6
mm wrote:
I have a string example like this
TSOP65P640X120-20N M 0 0 0 3 9 0 20 1 0 <snip> How do I get the string before the first number (TSOP)


Besides the other proposed approaches, maybe you'd like to try a more
generic one:

Public Function GetPrefix(ByVal Text As String, _
ByVal PrefixList As String) As String
Dim Size As Integer
For Each C As Char In Text
If PrefixList.IndexOf(C) >= 0 Then
Return Text.Substring(0, Size)
End If
Size += 1
Next
Return ""
End Function

Your string example could be parsed like this:

Dim Prefix as String = GetPrefix( _
"TSOP65P640X120-20N M 0 0 0 3 9 0 20 1 0", _
"0123456789")

HTH.

Regards,

Branco.

Jan 3 '06 #7

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

Similar topics

3
21013
by: Matt | last post by:
if (123 > 33) will return true and if ("123" > 33) will return true So my question is, if the above behaviors are the same?? If string is a number, and compare with another number, it will be the same behavior as compare 2 numbers?
21
3959
by: google | last post by:
I'm trying to implement something that would speed up data entry. I'd like to be able to take a string, and increment ONLY the right-most numerical characters by one. The type structure of the data that is in this field can vary. It's a list of mechanical equipment, and how it is designated varies based on how the customer has them labeled....
32
14762
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if ((someString.IndexOf("something1",0) >= 0) || ((someString.IndexOf("something2",0) >= 0) ||
6
7595
by: karthi | last post by:
hi, I need user defined function that converts string to float in c. since the library function atof and strtod occupies large space in my processor memory I can't use it in my code. regards, Karthi
13
3197
by: Freaker85 | last post by:
Hello, I am new at programming in C and I am searching a manner to parse a string into an integer. I know how to do it in Java, but that doesn't work in C ;o) I searched the internet but I didn't found it yet. help please thank you Freaker85
1
282
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - Why does 1+1 equal 11? or How do I convert a string to a number? ----------------------------------------------------------------------- Javascript variables are loosely typed: the conversion between a string and a number happens automatically. Since plus (+)...
8
4977
by: shapper | last post by:
Hello, I have a string which holds a text. Is it possible to create a substring which uses the first N words of that string? Thanks, Miguel
232
13066
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first set of examples, after decoding the HTML FORM contents, merely verifies the text within a field to make sure it is a valid representation of an...
3
2567
by: TamaThps | last post by:
I have an array of string values, and I need to access each character of the string individually. For instance I want my char variable to equal the first character in the string, and then compare it to character values using if statements. Later in the program I will need to not only access the first character but all of them individually in each...
0
7269
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7177
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7559
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7123
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5701
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5100
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4756
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
1611
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
811
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.