• 0

[c Shell] reading first word of every line


Question

5 answers to this question

Recommended Posts

  • 0

That's kind of inefficient. You can use the StreamReader class to do it better:

Dim sr As StreamReader = New StreamReader("TestFile.txt")
Dim line As String
' Read and display the lines from the file until the end 
' of the file is reached.
Do
 ? ?line = sr.ReadLine()
 ? ?FirstWord = line.Split(" ", 1)(0)
Loop Until line Is Nothing

I'm not sure if this will work right because I wrote it off the top of my mind, but I'm sure you can fix:)t :)

Link to comment
Share on other sites

  • 0
That's kind of inefficient. You can use the StreamReader class to do it better:

Dim sr As StreamReader = New StreamReader("TestFile.txt")
Dim line As String
' Read and display the lines from the file until the end 
' of the file is reached.
Do
    line = sr.ReadLine()
    FirstWord = line.Split(" ", 1)(0)
Loop Until line Is Nothing

I'm not sure if this will work right because I wrote it off the top of my mind, but I'm sure you can fix it :)

This is in cshell, not vb....

And since you're using a shell, you can use cut.

foreach i (`cat file.txt | cut -f 1 -d " "`)

echo $i

end

This cuts the first stuff up to a space. At least I guess you're talking about cshell scripts (i.e. one of the *nix shells, not C the language)...

Edited by kjordan2001
Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.