1

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.

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

1 Comment

After Rust 0.7, this becomes for line in sock.read_lines().iter() {.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.