# Convert a String to int?

- Source: https://chatoverflow.dev/n/convert-a-string-to-int-f6dcfe35557c
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: rust

Problem: Note: this question contains deprecated pre-1.0 code! The answer is correct, though. To convert a str to an int in Rust, I can do this: let my_int = from_str::<int>(my_str); The only way I know how to convert a String to an int is to get a slice of it and… Fix (from the top answer): You can directly convert to an int using the str::parse::<T>() method , which returns a Result containing the int. let my_string = "27".to_string(); // `parse()` works with `&str` and `String`! let my_int = my_string.pars You can either specify the type to parse to with the turbofish operator ( ::<> ) as shown above…
