0
start=AKS-RHzlSXSftLGYdBNk.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1&

For every instance of the word 'start' I need to be able to get the text after the first full stop, right up until the & symbol. E.g. 'eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1'.

There will be more than one instance of this. They will need to be appended to a listbox.

What is the simplest/quickest way to do this? (Using possibly streamreader - text file)

Ash King
  • 229
  • 5
  • 20
  • Does each instance of `start=` occur on a new line? – Andrew Morton Apr 28 '14 at 20:01
  • the file has random text within itself, but yes the `start=` begins on a new line. Just to let you know the file is roughly 500kb containing just under 33k lines. – Ash King Apr 28 '14 at 20:05
  • 500KB is nigh on negligible if you follow the method I suggested, but thanks for adding that potentially important information. – Andrew Morton Apr 28 '14 at 20:19

2 Answers2

1

The simplest and quickest way will be to read each line, and check if it .StartsWith("start="). If so, then get the .IndexOf(".") and the .IndexOf("&", <whereever the first indexOf was>). Get the .SubString which encompasses those two values. I'm sure you can write the code yourself from that ;)

Andrew Morton
  • 24,203
  • 9
  • 60
  • 84
0

I tested this function with a button click, output text each line on a textbox. I am sure you can adapt this to your code.

  Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
    txtResults.Text = ""
    Dim ParseString As String
    ParseString = "start=123341.23124&kjdshfkjsdaksdstart=1231.2321312&kadhskjashdkjastart=1231.23126789898&skjdfhkjsd"
    Dim Delimiters() As String = New String() {"start="}
    Dim Words() As String
    Words = ParseString.Split(Delimiters, CompareMethod.Text)
    For Each Part In Words
        Dim Middle As String
        Middle = Part.Split(".").Skip(1).Take(1).FirstOrDefault()
        Dim Good As String
        Good = Middle.Split("&").FirstOrDefault()
        txtResults.Text += Good + vbNewLine
    Next
End Sub

Output was

23124
2321312
23126789898

Added 31104 lines to a string and ran, took about 11 seconds to run on my laptop. Might be too slow for your app?

KRichardson
  • 990
  • 7
  • 12
  • It seems reasonable to assume that the OP has a fair amount of text to extract, so a [StringBuilder](http://msdn.microsoft.com/en-us/library/system.text.stringbuilder%28v=vs.110%29.aspx) would be more "performant". Also, appending text incrementally to a UI control is very much *not* the fastest way of accumulating a string. – Andrew Morton Apr 28 '14 at 20:17
  • thats not quite what the OP is after. they are after the text after the `.` after `start`. The OP refers to it as a `full stop`. – Ňɏssa Pøngjǣrdenlarp Apr 28 '14 at 20:19
  • this was just for a test to output to a UI control, as I didnt want to write any code that would not execute in some sort or fashion. The first loop could be a new line, or some other string if that is how the text is split up. – KRichardson Apr 28 '14 at 20:23