Results 1 to 8 of 8

Thread: Part of a string

  1. #1
    VBAX Regular
    Joined
    Aug 2019
    Posts
    54
    Location

    Part of a string

    Hi . I have a string like this "10_aString_1-1" ,now how can i get only the "aString_1"
    Thank you for your time
    Kostas

  2. #2
    VBAX Regular
    Joined
    Jan 2018
    Location
    The Netherlands
    Posts
    45
    Location
    A$=“10_aString_1-1”
    B$=Mid(A$,4,9)

  3. #3
    VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,710
    Location
    A$ = "x_xxx_xx_xx-x"
    B$ = Split(A$, "-", 1)
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  4. #4
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    That's wrong Sam, even removing the '1' from the Limit of the split stil leaves the first part of the string (10_) which the op doesn't want.
    Semper in excretia sumus; solum profundum variat.

  5. #5
    VBAX Regular
    Joined
    Aug 2019
    Posts
    54
    Location
    Hi Thank you all for your anwsers but i'd like to be more dynamic the search . For example if the string is "1003_twoString_12-1" or "10003_threeString_123-1" then how can i get it the "twoString_12" or "threeString_123"
    Regards
    Kostas

  6. #6
    VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,710
    Location
    Good eye. However, just removing the limit of Split make B$ an array with 2 elements

    B$ = Split(Split(A$, "-", 1), "_")(1) & "_" & Split(Split(A$, "-", 1), "_")(2)

    Better might be
    $B = Mid(A$, (Instr(A$, "_") + 1), (Len(A$) - (Instr(A$, "-") + 1)))
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  7. #7
    VBAX Regular
    Joined
    Aug 2019
    Posts
    54
    Location
    OK Thank you very much SamT

  8. #8
    VBAX Newbie
    Joined
    Mar 2020
    Posts
    3
    Location
    $B = Mid(A$, (Instr(A$, "_") + 1), (Len(A$) - (Instr(A$, "-") + 1)))

Posting Permissions

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