I have part numbers like:
I am trying to write a vbscript that will give me the 3 characters to the left of the dash so that I get "232" returned for either of these parts. Nothing I have tried seems to work! Can anyone help me on this?
Thank you all! I got this working. This was the final solution:
s = Field("Text File 1.box_label_print_db.Item")i = Instr(s, "-")if i >=1 Thend = TRIM(MID(Field("Text File 1.box_label_print_db.Item"), i-3, 3))
I don't do VB.NET but I can try to describe a solution:The second one is the easier of the two. Find the IndexOf the '-' and then return the Substring from 0 to the IndexOf the -.For the first one, you can build off the first. Take the resulting String and try to Convert it to a number. If it fails, you know there is an alpha/non-numeric somewhere in the substring. You'd have to loop character by character over the new substring to find the first index of a non-numeric character & then use the similar logic with IndexOf and Substring to get just the number.Any of this close to what you tried?
split the string by hyphen using Split()
then use Substring() to get last 3 characters
Not sure if VB script allows regex, but if it does you could just use a positive look ahead...d{3}(?=-)
Use function InStr(1, yourstring, "-", 1). It should return a position of the minus sign. Next, use function Left(yourstring, minusposition-1).it should return the left part without minus. Last, use Right(leftsidestring, 3) and this should return 232 in both cases. You can put everything in one line, but I think it would be better to do the data checks in between (for example if the minus does not exist in input).