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.
Printable View
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.
If it's a fixed number of chars at the end then use Left$() of Mid$() function:
mystring = Left$(mystring, Len(mystring) - 7)
or
mystring = Mid$(mystring, 1, Len(mystring) - 7)
Hello,
This is what you need ;)
VB Code:
Dim MyStr As String 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.Quote:
Originally Posted by DRI66
Have you tried what I posted, vert?
Actually, left() reduces the string to only its leftmost characters...the left characters will be retained and the rest removed.Quote:
Originally Posted by vert
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 :-)
Then you can use the Left$() or Mid$() functions like Rhino posted.
I haven't no..
and I am an idiot in VB so can you explain what does the code do?
Example:Quote:
Originally Posted by smUX
1) michaelA12345P1
2) johnC12345P2
I want to retain the michaelA and johnC.
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)
Thanks everyone!
I really am glad that this forum exists and I didn't learn a language that is totally obscure... lol....