View Full Version : [SOLVED:] Part of a string
ksilenio
04-26-2020, 01:57 AM
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
Hightree
04-26-2020, 03:23 AM
A$=“10_aString_1-1”
B$=Mid(A$,4,9)
A$ = "x_xxx_xx_xx-x"
B$ = Split(A$, "-", 1)
paulked
04-26-2020, 06:56 AM
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.
ksilenio
04-26-2020, 10:03 AM
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
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)))
ksilenio
04-26-2020, 11:34 AM
OK Thank you very much SamT
binu.b
04-27-2020, 05:40 AM
$B = Mid(A$, (Instr(A$, "_") + 1), (Len(A$) - (Instr(A$, "-") + 1)))
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.