Click to See Complete Forum and Search --> : [RESOLVED] Mid function
Academy
Oct 14th, 2006, 02:06 AM
Hi,
I hope somebody in the forum knows VB.6. I am looking for a function that does the samething as Mid function in VB.6. Please see the below sample.
Dim MyString, FirstWord
MyString = "Mid Function Demo" ' Create text string.
FirstWord = Mid(MyString, 1, 3) ' Returns "Mid".
Thanks.
ComputerJy
Oct 14th, 2006, 03:27 AM
What does it do? your example couldn't be more vague
CornedBee
Oct 14th, 2006, 04:48 AM
It's like String.substring, except I think Mid's last argument is the length of the substring, not the end index like in Java.
ComputerJy
Oct 14th, 2006, 04:52 AM
I don't think so, I found this example:' Creates text string.
Dim TestString As String = "Mid Function Demo"
' Returns "Mid".
Dim FirstWord As String = Mid(TestString, 1, 3)
' Returns "Demo".
Dim LastWord As String = Mid(TestString, 14, 4)
' Returns "Function Demo".
Dim MidWords As String = Mid(TestString, 5)
CornedBee
Oct 14th, 2006, 04:54 AM
Oh yeah, Mid is 1-based, while String.substring is 0-based. But aside from that, you just proved my point.
ComputerJy
Oct 14th, 2006, 05:08 AM
Oh yeah, Mid is 1-based, while String.substring is 0-based. But aside from that, you just proved my point.
err....I don't know
Why do they call it MID if it has nothing to do with Middle!! :confused:
CornedBee
Oct 14th, 2006, 05:09 AM
Well, it has. It takes a part in the middle of the string. As opposed to Beg and End, or whatever they're called, which take a part from the beginning and end of the string, respectively.
Why the designers of VB thought it necessary to have 3 functions is beyond me.
In Java, you do it all with String.substring(), String.length() and a bit of math that a 7-year-old can do.
Academy
Oct 14th, 2006, 11:52 AM
MyString = "Mid Function Demo" ' Create text string.
FirstWord = Mid(MyString, 1, 3) ' Returns "Mid".
It returns a string from MyString, starts from postion 1 and 3 characters long.
ComputerJy
Oct 14th, 2006, 02:05 PM
This is how its done in Java String MyString, FirstWord ;
MyString = "Mid Function Demo" ;
FirstWord = MyString.substring( 0, 3 ) ;
Academy
Oct 14th, 2006, 02:22 PM
Thanks
CornedBee
Oct 14th, 2006, 08:48 PM
And my posts didn't tell you this because ...?
AlnavPlatinum
Oct 19th, 2006, 03:43 PM
it actually does not do what you have talked (above). With the below code, it should start at a position 2 and returns 5 characters.
System.out.println(strFirstBigIn.substring(2,5)+"");
See the out put for more explaination:
Please enter your first BigInt
123456789
345
|2eM!x
Nov 10th, 2006, 07:21 PM
it actually does not do what you have talked (above). With the below code, it should start at a position 2 and returns 5 characters.
System.out.println(strFirstBigIn.substring(2,5)+"");
See the out put for more explaination:
Please enter your first BigInt
123456789
345
Im not seeing that anywhere in the thread..?
It goes from position 2 to position 5 which is 3 characters..where is the problem?
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.