How to convert a string pair to Pair?

Hello All,

I have a small file that currently exists with only 1 Line - Debug:True.
I want to convert that to Pair but it will not compile complaining that the right side of the equation is not a type pair:

Dim s(-1) As String = Split(FileString, ",")
Dim n As Integer = s.Ubound + 1
If n =0 Then Return -1

Var t As Pair = s(0)

Other than using mid to parse the line, which would be redundant (why use pair in this case) is there a simple way to coerce the string inside s(0) to a pair?

Thanks,
Tim

Pair accepts:

Var p As New Pair(1, 2)

or

Var p As Pair = 1 : 2

Try changing:

Var t As Pair = s(0)

to

Var t As Pair = s(0) : s(1)

I have to admit I was completely unaware of the Pair data type. But after a little experimentation this worked for me:

Var t As Pair = new Pair (s(0), s(1))

Why that way and not one of the ones I showed?

Is easier for my eyes like this:

Var t As new Pair(s(0), s(1))
1 Like

We typed our replies at the same time. Your post was not visible to me when I posted.

1 Like

Hi Alberto.
s(0) contains ‘Debug:True’
Currently there is no s(1)

S is an array of lines like shown above. The array is meant to read all of the lines (eventually there will be more) then s(1), s(2) will be populated…

I thought it would be faster/easier to use pair since it does its own parsing…

Since the variable has the correct format (‘Debug:True’ ) I was hoping that pair would accept it as that. Sadly it does not.

Tim

As far as I can tell (and remember I’m new to this data type), Pair does not do any parsing. You’ll still need to do the parsing yourself, as in:

var FileString as string = "Debug:True"
Var t As New Pair (FileString.NthField(":", 1), FileString.NthField(":", 2))
1 Like

In this case : is a character and not an operator, so it is not the same thing.

You are trying to do this:

Var t As pair = "Debug:True" //doesn't work

instead of:

Var t As pair = "Debug" : "True" //works
2 Likes

Thank you guys!

Christian Wheels answer works great.

Thanks everyone!
Tim

Depending on what your goal is a Dictionary could be an option.

@Alberto D - Yes, it could be but at least for now, I only need to read once and set some internal variables.

Thank you all again!
Tim