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

How to find the position of the first dash in a string

Rob
lets' say I have a value ABCD - 123

How can I return the position of the dash ?
Sep 28 '06 #1
8 2378
lets' say I have a value ABCD - 123
>
How can I return the position of the dash ?
Do you mean that you have a string containing "ABCD - 123"? If so, use
Instr().
Sep 28 '06 #2
x = instr("ABCD - 123", "-")

"Rob" <rw*****@comcast.netwrote in message
news:cO******************************@comcast.com. ..
lets' say I have a value ABCD - 123

How can I return the position of the dash ?

Sep 28 '06 #3
Dim s As String = "ABCD - 123"
s.IndexOf("-").ToString()

"Rob" <rw*****@comcast.netwrote in message
news:cO******************************@comcast.com. ..
lets' say I have a value ABCD - 123

How can I return the position of the dash ?

Sep 28 '06 #4
"Rob" <rw*****@comcast.netschrieb:
lets' say I have a value ABCD - 123

How can I return the position of the dash ?
'Strings.InStr', 'String.IndexOf'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Sep 28 '06 #5
dim i as integer = YourString.IndexOf("-")
if i < 0 the pattern does not exist in the string, otherwise, "i" has
the offset of the start of the string.

Rob wrote:
lets' say I have a value ABCD - 123

How can I return the position of the dash ?
Sep 28 '06 #6

Rob wrote:
lets' say I have a value ABCD - 123

How can I return the position of the dash ?
Dim s As String = "ABCD - 123"
Console.WriteLine (s.IndexOf ("-"))

or

Dim s As String = "ABCD - 123"
Console.WriteLine (InStr (s, "-"))

--
Tom Shelton

Sep 28 '06 #7

AMercer wrote:
lets' say I have a value ABCD - 123

How can I return the position of the dash ?

Do you mean that you have a string containing "ABCD - 123"? If so, use
Instr().
The "proper" .NET way would be to use the IndexOf method.

Sep 28 '06 #8
za***@construction-imaging.com wrote:
AMercer wrote:
>>lets' say I have a value ABCD - 123

How can I return the position of the dash ?

Do you mean that you have a string containing "ABCD - 123"? If so,
use Instr().

The "proper" .NET way would be to use the IndexOf method.
But surely, then you should check that the string isn't Nothing first or you
could get an ArgumentNullException . Why do you consider the VB.NET method
as not "proper" when programming in VB.NET? Would you exclusively use
"String.Concat" rather than "&" ?.

Andrew
Sep 29 '06 #9

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

Similar topics

12
by: Stan Brown | last post by:
I've been thinking about float-ing a span versus float-ing a div, and the same for absolute positioning. When what is floated or positioned is a short chunk of text, I don't see any _visual_...
2
by: Faz | last post by:
I am trying to extract text before a certain character appears in a string. This character is the letter "C". Here is some sample data - the field is called REFERENCE_2: REFERENCE_2...
1
by: Sue | last post by:
Hello I'm new to this Regular Expression and need some help. I want to restrict what the user types in a text box. The User can type only A-Z, a-z, 0-9, spaces, comma, dash, period, single...
4
by: KL | last post by:
Hello again, I am still working on this homework assignment and have hit a wall. I have a list that I want to fill with all occurences of img tags from a big string of html code. So I have a...
3
by: Henry Stockbridge | last post by:
Hi, I am trying to write query expression that finds the position of the first number in a string. So, this recordset... DUS2345.4 D2789.6 .... would return the following positons
6
by: Registered User | last post by:
Hi experts, I'm trying to write a program to solve the following exercise: Accept three strings from the user. Find the first occurrence of the first string in the third string. If it is present...
3
by: Edwin Smith | last post by:
Hello: I have the following code which works on a DataGridView binding source: private void textBox1_TextChanged(object sender, EventArgs e) { this.pATIENTSBindingSource.Position =...
11
by: Ko van der Sloot | last post by:
Hello I was wondering which behaviour might be expected (or is required) for the following small program. I would expect that find( "a", string::npos ) would return string::npos but is seems to...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.