Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting part of a string

Status
Not open for further replies.

A1METALHEAD

Programmer
May 21, 2004
76
US
how do you get a part of a string? like if i wanted to get the first letter of "hello world"?
 
Left() function.

Answers to these types of questions can be found by pressing your F1 button.

*cLFlaVA
----------------------------
A polar bear walks into a bar and says, "Can I have a ... beer?"
The bartender asks, "What's with the big pause?
 
RiverGuy

"OldString.SubString(1,1)"
Two things are wrong.
1 - .Net Framework is 0-relative so you need
OldString.SubString(0,1)
to get the first character.

2 - if OldString.Length = 0 then an exception will be thrown.

So
if OldString.Length > 0 then
NewString = OldString.SubString(0,1)
else
NewString = String.Empty
End if



Forms/Controls Resizing/Tabbing
Compare Code
Generate Sort Class in VB
Check To MS)
 
My mistake John. Was in a hurry. Wrote it to mainly show the new .Net methodology as opposed to VB6 compatibility.
 
BTW left() right() and mid() are perfectly acceptable and have some errorhandling included. for example they wont produce an error when the string is 0 length.

they produce the same IL code as substring

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
What a wonderfull world - Louis armstrong
 
or you could include the microsoft.visualbasic in c#. all the comforts from home...

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
What a wonderfull world - Louis armstrong
 
Yes, but what if a prospective future employer will not allow that. I want to be able to claim "pure" C#. Bottom line is, I'll follow the money. Right or wrong. C# pays LOTS more.

See Visual Studio then click on C# gets th big bucks.

Language used Average salary
C# $98,813
Visual Basic .NET $72,959
Visual Basic 4.0, 5.0, or 6.0 $72,461
Visual C++ 6.0 $75,500

C# Gets the Big Bucks. Last year, C# developers earned around $5,000 more than Visual Basic .NET developers. This year that gap has widened to an astounding $26,000. It literally pays to know C#—whereas salaries for developers who program primarily in Visual C++ remain flat with last year's numbers.


Forms/Controls Resizing/Tabbing
Compare Code
Generate Sort Class in VB
Check To MS)
 
well, im not in it for the money.

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
What a wonderfull world - Louis armstrong
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top