|
-
Nov 23rd, 2010, 08:54 AM
#1
Thread Starter
Lively Member
[RESOLVED] Line to array help?
Hello Everyone!
I am trying to take a line from a text file and get the second half of the line "my.settings.useqs = true" is my example and i want to get true out of the line and then make a textbox contain the text aftter the = sign basicly.
http://www.vbforums.com/showthread.php?t=626903
I posted something similar but i am having a hard time trying to figure this out. I also don't really understand how I used it in the first place.
If anyone can help me that would be great!
Thanks!
-
Nov 23rd, 2010, 09:00 AM
#2
Re: Line to array help?
You've already been shown in that other thread how to split a string on an '=' and get the second half. That's all you need to do, once you have the string. To get that, you can either open a StreamReader and call ReadLine until you get the desired line, or you can call File.ReadAllLines (which is also mentioned in that other thread) to get a String array and then get the desired element from that.
-
Nov 23rd, 2010, 09:09 AM
#3
Thread Starter
Lively Member
Re: Line to array help?
Yes i am aware of that but i don't understand the part about using a textbox this time. I used a listbox last time and used display member and such then. Textboxs, don't have display member so that is were my problem comes in.
Code:
Dim items = (From line In IO.File.ReadAllLines(FILE_NAME) Where line.StartsWith("my.settings") Let parts = line.Split(New String() {" = "}, StringSplitOptions.None)
Select New With {.setting = parts(0).Split("="c)(1), .value = parts(1).Split("="c)(1)}).ToArray()
I think i made a mistake - the bolded code is in yellow and tells me:
"Index was outside the bounds of the array."
My file contains this
Code:
2.1.0.0
my.settings.font = "Arial"
my.settings.indent = "10"
-
Nov 23rd, 2010, 09:55 AM
#4
Re: Line to array help?
When you call Split it returns a String array. Wen you get an element from a string array it returns a String. The Text property of a TextBox is type String. You assign the String to the property.
-
Nov 23rd, 2010, 10:00 AM
#5
Thread Starter
Lively Member
Re: Line to array help?
i somewhat understand but not fully. Would you be able to explain more please?
Appreciate the help
-
Nov 23rd, 2010, 10:09 AM
#6
Re: Line to array help?
This is doing almost exactly what you want:
Code:
.setting = parts(0).Split("="c)(1)
You just have to assign the String to the Text of the TextBox instead of the 'setting' property of a dynamically created object.
-
Nov 23rd, 2010, 10:15 AM
#7
Re: Line to array help?
The file that you are showing is much different than the file that you were showing in that other thread. The code certainly isn't going to work the same for one as for the other. For example, in the first thread, there were two = signs, but in the current file, as you have shown it, there is only one per line. Therefore, when you split on =, there will be a parts(0) and a parts(1), but neither of them will have = signs in them, so if you do split them on = (which is what you are doing), then the resulting arrays will only have one element. Therefore, when you attempt to look at the second element with (1), you are out of bounds.
My usual boring signature: Nothing
 
-
Nov 23rd, 2010, 10:16 AM
#8
Re: Line to array help?
Ah, JMC has not gone to bed yet.
My usual boring signature: Nothing
 
-
Nov 23rd, 2010, 10:20 AM
#9
Re: Line to array help?
Any moment now. It's 2:20 AM. Yawwwwnn! Tehe. I just yawned when I typed "yawn". Maybe I should type "get rich".
-
Dec 1st, 2010, 10:38 AM
#10
Thread Starter
Lively Member
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|