Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,
I'm using VB.Net 2010 and i want take string between two strings.
my string = "ÿÿÿÿÿÿÿÿ^2hold up.._AFC"
How Can I take this "^2hold up.."(Lenght is never same.)
Posted
Comments
Basmeh Awad 27-May-13 11:38am    
did you got the solution??

Have you ever heard about RegEx[^]?

If you would like to find 2hold up, please use it:
VB
Imports System.Text.RegularExpressions

Module Module1

    Sub Main()
        Dim sText As String = "ÿÿÿÿÿÿÿÿ^2hold up.._AFC"
        Dim sPattern As String = "\b*(\^2hold up..)*\b"
        Dim rx As Regex = New Regex(sPattern, RegexOptions.Singleline)

        For Each m As Match In rx.Matches(sText)
            Console.WriteLine(m.Value)
        Next

        Console.ReadKey()
    End Sub

End Module


If not, please, let me know and i'll try to find you proper pattern.
 
Share this answer
 
v3
Comments
Sergey Alexandrovich Kryukov 28-May-13 0:50am    
It looks like your logic is also wrong, Maciej. OP wants to get "^2holp up". If so, it means this part of string is unknown. So, you cannot use it in your pattern. And if it is known, you would find whatever is already known, so it would be at least "if {inputString.Contains(...)} ...".

Perhaps, right answer would be: "Dear OP, you did not specify what part(s) of the string is supposed to be known?" or like this: "giving one example does not mean specification of anything...".

—SA
Maciej Los 28-May-13 1:55am    
Thank you for your suggestion, Sergey.
VB
Dim s As String
      s = "ÿÿÿÿÿÿÿÿ^2hold up.._AFC"
      Dim start = s.IndexOf("ÿÿÿÿÿÿÿÿ") + Len("ÿÿÿÿÿÿÿÿ")
      Dim limit = s.IndexOf("_AFC") - start
      s = s.Substring(start, limit)

Happy Coding!
:)
 
Share this answer
 
Comments
Maciej Los 27-May-13 9:22am    
I think your logic is wrong... Why? Lenght is never same, so we do not know the string before and after searched string ;(
Aarti Meswania 27-May-13 9:39am    
it will work
try input like this...
s = "43345345345345ÿÿÿÿÿÿÿÿ^2hold up.._AFCfgffhfhfhfhfhfhfhf"
still it will answer same
:)
Maciej Los 27-May-13 11:13am    
Try input like this: 433453453sderf45345^2hold up.._g5476ffhfhfhfhfhfhfhf
:)
Aarti Meswania 27-May-13 9:41am    
OP wants "^2hold up.." as result
in your solution you are feeding directly o/p in process, which he want as result
:)

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