views:

362

answers:

3

Does any one know how can I cut the 1st 3 char in a string in vb 2008?

For example: Dim i As String = "ABCDEF";

I want to only cut the 1st 3 char and the system will only display "ABC" after the 'cut' action done.

+1  A: 

You want Substring.

Promit
+8  A: 

That would be

i.Substring(0, 3)
MiseryIndex
A: 

For this type of thing, you should look into using the "Left" function. "Mid" would also work.

majestiq
-1 for classic VB holdover function rather than a standard string function.
Adam Robinson
I was just going to ask about it. I created a new C# app in VS, and it had no idea what Left or Mid was
MiseryIndex
oh come on.. it works doesn't it?
majestiq
+1 since such a trivial downrate just seems mean.
Promit
@majestiq: Yes, it would work, but it's a construct known only to VB within the .NET languages. You have a rich, powerful library you're sitting on top of. Use the functions as they're designed. mid, left, etc. were ONLY left in VB so that classic VB projects could be more easily imported. They should never be used in new code.
Adam Robinson
@Promit: you're entitled to your opinion, of course, but the fact of the matter is it's not a good...or perhaps "advisable" is a better word...solution to the issue, and the idea being put forth in this answer should be discouraged. Hence the downvote.
Adam Robinson