none
Read line till ","

    Question

  • Hello, im reading lines from an .txt file how can i read line till "," separator?
    For example:

    Hello, my name is John.

    Output will be: Hello

    Thanks

    Monday, March 20, 2017 2:46 PM

Answers

  • Hello, im reading lines from an .txt file how can i read line till "," separator?
    For example:

    Hello, my name is John.

    Output will be: Hello

    Thanks

    Use .Substring and .IndexOf:

            Dim s As String = "Hello, my name is John."
    
            If s.Contains(","c) Then
                s = s.Substring(0, s.IndexOf(","c))
            End If


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    • Marked as answer by extream87 Monday, March 20, 2017 3:35 PM
    Monday, March 20, 2017 2:52 PM

All replies

  • Hello, im reading lines from an .txt file how can i read line till "," separator?
    For example:

    Hello, my name is John.

    Output will be: Hello

    Thanks

    Use .Substring and .IndexOf:

            Dim s As String = "Hello, my name is John."
    
            If s.Contains(","c) Then
                s = s.Substring(0, s.IndexOf(","c))
            End If


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    • Marked as answer by extream87 Monday, March 20, 2017 3:35 PM
    Monday, March 20, 2017 2:52 PM
  • You cannot "Read" till a comma. 

    You get all the data, and then you can split that and for that are many methods.

    One of the other ways than Frank has shown. 

    "Hello, my name is John.".split(","c)(0)

    results in "Hello" 


    Success
    Cor


    Monday, March 20, 2017 3:12 PM
  • Thanks both :D
    Monday, March 20, 2017 3:35 PM
  • Thanks both :D

    I'm glad it helped. :)

    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Monday, March 20, 2017 3:39 PM