Results 1 to 11 of 11

Thread: [RESOLVED] Removing characters from a string?

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    32

    Resolved [RESOLVED] Removing characters from a string?

    How do I remove 7 last character in Xyzaaa1234567 so that only Xyzaaa is displayed?

    I've only learnt about extracting characters but never had to remove them before.

    Thanks.

  2. #2

  3. #3
    Lively Member
    Join Date
    Jan 2007
    Location
    Belgium
    Posts
    104

    Re: Removing characters from a string?

    Hello,

    This is what you need

    VB Code:
    1. Dim MyStr As String
    2. MyStr = Left("Xyzaaa1234567", 6)

    Best Regards,
    Didier.

  4. #4

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    32

    Re: Removing characters from a string?

    Quote Originally Posted by DRI66
    Hello,

    This is what you need

    VB Code:
    1. Dim MyStr As String
    2. MyStr = Left("Xyzaaa1234567", 6)

    Best Regards,
    Didier.
    The problem with this is that it extracts the first 6 letters. In my program only the last 7 letters are CONSTANT and I need to remove that constant letters.

  5. #5

  6. #6
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: Removing characters from a string?

    Quote Originally Posted by vert
    The problem with this is that it extracts the first 6 letters. In my program only the last 7 letters are CONSTANT and I need to remove that constant letters.
    Actually, left() reduces the string to only its leftmost characters...the left characters will be retained and the rest removed.

    However, how about you give us something to work with here...The stuff you're trying to remove, is it ALWAYS the same text, is it ALWAYS numbers, is it ALWAYS letters? If it's always the same, you can use a very simple replace() function to remove it, if it's always letters or numbers you can use a modified function (one that uses replace()) that can remove them :-)
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  7. #7
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Removing characters from a string?

    Then you can use the Left$() or Mid$() functions like Rhino posted.

  8. #8

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    32

    Re: Removing characters from a string?

    I haven't no..

    and I am an idiot in VB so can you explain what does the code do?

  9. #9

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    32

    Re: Removing characters from a string?

    Quote Originally Posted by smUX
    Actually, left() reduces the string to only its leftmost characters...the left characters will be retained and the rest removed.

    However, how about you give us something to work with here...The stuff you're trying to remove, is it ALWAYS the same text, is it ALWAYS numbers, is it ALWAYS letters? If it's always the same, you can use a very simple replace() function to remove it, if it's always letters or numbers you can use a modified function (one that uses replace()) that can remove them :-)
    Example:

    1) michaelA12345P1
    2) johnC12345P2

    I want to retain the michaelA and johnC.

  10. #10
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: Removing characters from a string?

    Aha...I see what your problem with the code is now...RhinoBull's code should work fine...it basically looks at the length of the string and reduces it by 7 characters (taking the leftmost ones and removing the last 7)
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  11. #11

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    32

    Re: Removing characters from a string?

    Thanks everyone!

    I really am glad that this forum exists and I didn't learn a language that is totally obscure... lol....

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