How do I know which are the first characters before "/"? asp.net vb.net -
i have string that:
dim temp string = "batch 634239100a/45 pcs booked out vladut moraru on 10/15/2015"
or
dim temp string = "batch 322.3/4 pcs booked out vladut moraru on 10/15/2015"
or
dim temp string = "batch 322/3/4 pcs booked out vladut moraru on 10/15/2015"
i want display 322/3/
batch : 322/3/ pcs : 4
i want display : 322/3/
of string
i thought i'd find 322/3/4
, give split after last /
, find value before /
, how?
the easiest thing use regularexpression, there limitations this, you're including date in string.
if numbers in format of nnn/nnn/nn
and appear before date work...
dim regexmatch system.text.regularexpressions.match regexmatch = system.text.regularexpressions.regex.match(mystring, "(\d{3}/\d{3})/(\d{2})") if regexmatch.success dim batch string = regexmatch.groups(1).value dim pcs string = regexmatch.groups(2).value end if
the regex (\d{3}/\d{3})/(\d{2})
breaks down as...
(
create capture group\d{3}
3 numeric digits (0-9)/
character\d{3}
3 numeric digits (0-9))
close , store capture group/
character(
create capture group\d{2}
2 numeric digits (0-9))
close , store capture group
(note, in asp.net not required escape /
character... in other regex parsers necessary.)
if don't need pcs
retrieved, remove 2nd capture group (so looks (\d{3}/\d{3})/\d{2}
)... need remove regexmatch.groups(2).value
otherwise you'll exception.
if need check variable number of digits use format of \d{3,5}
mean minimum of 3 , maximum of 5 numeric digits.
update - based on new information provided op.
use expression: "batch (.+)/(\d+) pcs"
regexmatch = system.text.regularexpressions.regex.match(mystring, "batch (.+)/(\d+) pcs", system.text.regularexpressions.regexoptions.ignorecase)
Comments
Post a Comment