mirror of
https://github.com/Dhghomon/easy_rust
synced 2024-11-17 15:29:51 +00:00
deploy: 816acf86d5
This commit is contained in:
parent
470201ae77
commit
51fce38f29
@ -180,10 +180,7 @@ fn main() {
|
||||
}
|
||||
</code></pre></pre>
|
||||
<p>Here is what an output output looks like:</p>
|
||||
<pre><pre class="playground"><code class="language-rust">
|
||||
<span class="boring">#![allow(unused)]
|
||||
</span><span class="boring">fn main() {
|
||||
</span>Please type something, or x to escape:
|
||||
<pre><code class="language-text">Please type something, or x to escape:
|
||||
something
|
||||
You wrote something
|
||||
|
||||
@ -198,13 +195,9 @@ You wrote x
|
||||
|
||||
x
|
||||
You wrote x
|
||||
<span class="boring">}
|
||||
</span></code></pre></pre>
|
||||
</code></pre>
|
||||
<p>It takes our input and gives it back, and it even knows that we typed <code>x</code>. But it doesn't exit the program. The only way to get out is to close the window, or type ctrl and c. Let's change the <code>{}</code> to <code>{:?}</code> in <code>println!</code> to get more information (or you could use <code>dbg!(&input_string)</code> if you like that macro). Now it says:</p>
|
||||
<pre><pre class="playground"><code class="language-rust">
|
||||
<span class="boring">#![allow(unused)]
|
||||
</span><span class="boring">fn main() {
|
||||
</span>Please type something, or x to escape:
|
||||
<pre><code class="language-text">Please type something, or x to escape:
|
||||
something
|
||||
You wrote "something\r\n"
|
||||
Something else
|
||||
@ -213,8 +206,7 @@ x
|
||||
You wrote "x\r\n"
|
||||
x
|
||||
You wrote "x\r\n"
|
||||
<span class="boring">}
|
||||
</span></code></pre></pre>
|
||||
</code></pre>
|
||||
<p>This is because the keyboard input is actually not just <code>something</code>, it is <code>something</code> and the <code>Enter</code> key. There is an easy method to fix this called <code>.trim()</code>, which removes all the whitespace. Whitespace, by the way, is all <a href="https://doc.rust-lang.org/reference/whitespace.html">these characters</a>:</p>
|
||||
<pre><code class="language-text">U+0009 (horizontal tab, '\t')
|
||||
U+000A (line feed, '\n')
|
||||
@ -229,7 +221,7 @@ U+2028 (line separator)
|
||||
U+2029 (paragraph separator)
|
||||
</code></pre>
|
||||
<p>So that will turn <code>x\r\n</code> into just <code>x</code>. Now it works:</p>
|
||||
<pre><code>use std::io;
|
||||
<pre><pre class="playground"><code class="language-rust">use std::io;
|
||||
|
||||
fn main() {
|
||||
println!("Please type something, or x to escape:");
|
||||
@ -242,7 +234,7 @@ fn main() {
|
||||
}
|
||||
println!("See you later!");
|
||||
}
|
||||
</code></pre>
|
||||
</code></pre></pre>
|
||||
<p>Now it will print:</p>
|
||||
<pre><code class="language-text">Please type something, or x to escape:
|
||||
something
|
||||
|
20
print.html
20
print.html
@ -11077,10 +11077,7 @@ fn main() {
|
||||
}
|
||||
</code></pre></pre>
|
||||
<p>Here is what an output output looks like:</p>
|
||||
<pre><pre class="playground"><code class="language-rust">
|
||||
<span class="boring">#![allow(unused)]
|
||||
</span><span class="boring">fn main() {
|
||||
</span>Please type something, or x to escape:
|
||||
<pre><code class="language-text">Please type something, or x to escape:
|
||||
something
|
||||
You wrote something
|
||||
|
||||
@ -11095,13 +11092,9 @@ You wrote x
|
||||
|
||||
x
|
||||
You wrote x
|
||||
<span class="boring">}
|
||||
</span></code></pre></pre>
|
||||
</code></pre>
|
||||
<p>It takes our input and gives it back, and it even knows that we typed <code>x</code>. But it doesn't exit the program. The only way to get out is to close the window, or type ctrl and c. Let's change the <code>{}</code> to <code>{:?}</code> in <code>println!</code> to get more information (or you could use <code>dbg!(&input_string)</code> if you like that macro). Now it says:</p>
|
||||
<pre><pre class="playground"><code class="language-rust">
|
||||
<span class="boring">#![allow(unused)]
|
||||
</span><span class="boring">fn main() {
|
||||
</span>Please type something, or x to escape:
|
||||
<pre><code class="language-text">Please type something, or x to escape:
|
||||
something
|
||||
You wrote "something\r\n"
|
||||
Something else
|
||||
@ -11110,8 +11103,7 @@ x
|
||||
You wrote "x\r\n"
|
||||
x
|
||||
You wrote "x\r\n"
|
||||
<span class="boring">}
|
||||
</span></code></pre></pre>
|
||||
</code></pre>
|
||||
<p>This is because the keyboard input is actually not just <code>something</code>, it is <code>something</code> and the <code>Enter</code> key. There is an easy method to fix this called <code>.trim()</code>, which removes all the whitespace. Whitespace, by the way, is all <a href="https://doc.rust-lang.org/reference/whitespace.html">these characters</a>:</p>
|
||||
<pre><code class="language-text">U+0009 (horizontal tab, '\t')
|
||||
U+000A (line feed, '\n')
|
||||
@ -11126,7 +11118,7 @@ U+2028 (line separator)
|
||||
U+2029 (paragraph separator)
|
||||
</code></pre>
|
||||
<p>So that will turn <code>x\r\n</code> into just <code>x</code>. Now it works:</p>
|
||||
<pre><code>use std::io;
|
||||
<pre><pre class="playground"><code class="language-rust">use std::io;
|
||||
|
||||
fn main() {
|
||||
println!("Please type something, or x to escape:");
|
||||
@ -11139,7 +11131,7 @@ fn main() {
|
||||
}
|
||||
println!("See you later!");
|
||||
}
|
||||
</code></pre>
|
||||
</code></pre></pre>
|
||||
<p>Now it will print:</p>
|
||||
<pre><code class="language-text">Please type something, or x to escape:
|
||||
something
|
||||
|
Loading…
Reference in New Issue
Block a user