Results 1 to 13 of 13

Thread: [RESOLVED] Mid function

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2003
    Posts
    108

    Resolved [RESOLVED] Mid function

    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.

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Mid function

    What does it do? your example couldn't be more vague
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: Mid function

    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.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Mid function

    I don't think so, I found this example:
    VB Code:
    1. ' Creates text string.
    2. Dim TestString As String = "Mid Function Demo"
    3. ' Returns "Mid".
    4. Dim FirstWord As String = Mid(TestString, 1, 3)
    5. ' Returns "Demo".
    6. Dim LastWord As String = Mid(TestString, 14, 4)
    7. ' Returns "Function Demo".
    8. Dim MidWords As String = Mid(TestString, 5)
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: Mid function

    Oh yeah, Mid is 1-based, while String.substring is 0-based. But aside from that, you just proved my point.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  6. #6
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Mid function

    Quote Originally Posted by CornedBee
    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!!
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: Mid function

    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.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jan 2003
    Posts
    108

    Re: Mid function

    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.

  9. #9
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Mid function

    This is how its done in Java
    Code:
        String MyString, FirstWord ;
        MyString = "Mid Function Demo" ;
        FirstWord = MyString.substring( 0, 3 ) ;
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Jan 2003
    Posts
    108

    Re: Mid function

    Thanks

  11. #11
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: [RESOLVED] Mid function

    And my posts didn't tell you this because ...?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  12. #12
    Lively Member
    Join Date
    May 2002
    Posts
    118

    Re: [RESOLVED] Mid function

    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

  13. #13
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: [RESOLVED] Mid function

    Quote Originally Posted by AlnavPlatinum
    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width