Click here to Skip to main content
15,917,608 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys,

I have a string like that:

Dim temp As String = "Batch 235/689/45 pcs booked out by vladut moraru on 10/15/2015"

I want to display 235/689

Batch is : 235/689
PCS is : 45

I want to display just : 235/689 of all string

I thought I'd find 235/689/45 and then to give it split after the last "/" and find value from before the "/", but how?

Thanks a lot!
Posted
Comments
Krunal Rohit 15-Oct-15 2:52am    
Don't repost. Use the Improve Question widget & update your question.3
http://www.codeproject.com/Questions/1039785/How-do-I-find-the-last-digit-of-the-sequence-with

-KR
MoraruVladut 15-Oct-15 2:56am    
Is another question. Is not repost

Simplest way is to use a Regex:
(?<Batch>\d+\/\d+)\/(?<PCS>\d+).*$

Should do it.
 
Share this answer
 
Comments
MoraruVladut 15-Oct-15 2:58am    
I don't understand, please put here in code please?
OriginalGriff 15-Oct-15 3:11am    
What part don't you understand?
A regular expression would be perfect for that:
VB
Imports System.Text.RegularExpressions
// ...
Dim input As String = "Batch 235/689/45 pcs booked out by vladut moraru on 10/15/2015"

Dim regexString As String = "^Batch (?<Batch>[\d]{3}/[\d]{3})/(?<PCS>[\d]{2}).*$"

Dim regex As Regex = New Regex(regexString, RegexOptions.Compiled Or RegexOptions.CultureInvariant)

Dim m As Match = regex.Match(input)

Dim batch As String = m.Groups("Batch").Value
Dim pcs As String = m.Groups("PCS").Value

'' Yields batch = "235/689", pcs = "45"

Hope this helps.
 
Share this answer
 
v6
Comments
MoraruVladut 15-Oct-15 3:09am    
This code is not for Visual Web developer :-?
phil.o 15-Oct-15 3:18am    
Sorry, I changed it for VB.
I have solution here:
VB
Dim regExMatch2 As System.Text.RegularExpressions.Match
                           regExMatch = System.Text.RegularExpressions.Regex.Match(CheckIfBooked, "Batch (.+)/\d+ pcs", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                           regExMatch2 = System.Text.RegularExpressions.Regex.Match(CheckIfBooked, "Batch (.+)/(\d+) pcs", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                           If regExMatch.Success Then
                               batch = regExMatch.Groups(1).Value
                           End If



Thanks a lot
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900