Link to home
Start Free TrialLog in
Avatar of CFIL
CFILFlag for United Kingdom of Great Britain and Northern Ireland

asked on

separate (") Char on a file (console application)

Dear experts,

I have a problem of separating some text with String.Split() function, the text is like this

The text is look like this:
"1", "Hi", "Test"
"2", "Hello", "B"

I have learned here to divied it by (,) chat, by this code:
Dim values() As String
    For Each sLine In arrText
            values = sLine.Split(",")
            For i As Integer = 0 To values.GetUpperBound(0)
                Console.WriteLine(i & ": " & values(i))
            Next
    Next

The output will be like this:
0: "1"
1:  "Hi"
2:  "Test"
0: "2"
1:  "Hello"
2:  "B"

How can sepearte them again by this (") char, I guess there is sonething like this in other langugeraes:
  values = sLine.Split('"%"')

So I want the output like this:

0: 1
1:  Hi
2:  Test
0: 2
1:  Hello
2:  B

Hope to find answers and thanks in advannce,
Regards.
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

question: do you simply want to remove the quotes, or left/right trim?
check out the string functions for Replace, TrimLeft and TrimRight, to start with
Avatar of CFIL

ASKER

Hi,

I want to delete all the quotes and (,) so the result should be something like this:
0: 1
1:  Hi
2:  Test
0: 2
1:  Hello
2:  B

Thanks in advance
so:
Dim values() As String
    For Each sLine In arrText
            values = sLine.Split(",")
            For i As Integer = 0 To values.GetUpperBound(0)
                Console.WriteLine(i & ": " & values(i).Replace('"', '') )
            Next
    Next

Open in new window

Avatar of CFIL

ASKER

Hi, Thanks for the reply,

I have got this error:
Error    1    Expression expected.  

Avatar of CFIL

ASKER

The error in this line:
  Console.WriteLine(i & ": " & values(i).Replace('"', '') )
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CFIL

ASKER

Grate, thanks man for the help.
Avatar of CFIL

ASKER

Thx