Athabaska Dick
Athabaska Dick

Reputation: 4281

How to iterate array of strings in Rust 0.7

How do I iterate through array of strings in Rust 0.7?

My array (or vector?) of strings is returned by sock.read_lines(); and I would like to print the contents of the array line by line. I dont quite understand how to do it since Rust documentation is incomplete and too sparse at the moment.

Upvotes: 1

Views: 2797

Answers (1)

Vladimir Matveev
Vladimir Matveev

Reputation: 128051

If sock.read_lines() returns something of type ~[~str] then you can iterate through this vector with the following code:

for sock.read_lines().iter().advance |line| {
    // Do somthing with line
}

This is described in containers and iterators tutorial which is accessible from the main tutorial, see links at the bottom.

Upvotes: 5

Related Questions