SteveL13
asked on
How get 4 characters from a string of characters
If I have this string of characters in a text field on a form... "80522526J142-101" How can I "pull" the "J142" portion of it out for use in another text field on a form? It will always be the 4 characters prior to the hyphen.
You could do this with a simple Regex. The following will match the 4 characters immediately preceeding a '-' character.
var testString = '80522526J142-101';
alert(testString.match(/(.{4})(?=-)/));
Corrected Code
res: Mid("yourString",Instr(1," yourString ", "-")-5,4)
res: Mid("yourString",Instr(1,"
ASKER
This didn't work: Mid("yourString",Instr(1," yourString ", "-")-5,Instr(1,"yourString ", "-")-1)
and
what is Regex?
and
what is Regex?
Sorry, slight edit to above...
var testString = '80522526J142-101';
alert(testString.match(/(.{4})(?=-)/)[0]);
This is just in case your string contains more than 1 '-' character. If you need to respond to multiple matches then the logic gets a little more complex.
ASKER
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Had to modify slightly:
Code: Mid([PartN],InStr(1,[PartN ],"-")-4,4 )
Code: Mid([PartN],InStr(1,[PartN
pls try
res: Mid("yourString",Instr(1,"
Regards