Rust Programming Tutorial #33 - String Methods

แชร์
ฝัง
  • เผยแพร่เมื่อ 23 ธ.ค. 2024

ความคิดเห็น •

  • @dcode-software
    @dcode-software  7 ปีที่แล้ว

    Check the video I did earlier on Strings here: th-cam.com/video/ABYdoxzNJJ8/w-d-xo.html

  • @a_maxed_out_handle_of_30_chars
    @a_maxed_out_handle_of_30_chars ปีที่แล้ว +1

    simple and to the point, thank you :)

  • @jameslay6505
    @jameslay6505 2 ปีที่แล้ว

    Finally someone actually talking about using strings and not just talking about what slices are.

  • @ssss8541
    @ssss8541 2 ปีที่แล้ว

    Hi, are you planning on continuing this series?

  • @sakuranooka
    @sakuranooka 3 ปีที่แล้ว

    Why, in the replacement example, my_string doesn't have to be mutable?

  • @rinitvergil1784
    @rinitvergil1784 3 ปีที่แล้ว

    how can i remove duplicates from a string??

  • @CunningBard
    @CunningBard 2 ปีที่แล้ว

    At 5:20 i was saying "that wont work, that wont work", then i was confused when it ran then realized he didn't print the vector

  • @jacksmith3386
    @jacksmith3386 7 ปีที่แล้ว

    Can you explain the filter function?

    • @dcode-software
      @dcode-software  7 ปีที่แล้ว

      +Jack Smith I haven't heard of the filter function on strings, do you have a link for documentation on it?

  • @TheOnlyJura
    @TheOnlyJura 6 ปีที่แล้ว +1

    how come I couldn't find how to get a character at an index on google, does no one need it ?

    • @djbailey1982
      @djbailey1982 5 ปีที่แล้ว +1

      This link gives a good, if technical breakdown of why that is: doc.rust-lang.org/book/ch08-02-strings.html#storing-utf-8-encoded-text-with-strings
      The brief (and mangled) version is that international character sets may store a single display character as multiple bytes... they may even store the diacritic marks separately from the character! So instead of giving you a default way of indexing a string that is likely to lead you into trouble down the road (say you make an international app), they make you deal with the trouble up-front (which seems to be an operating principle in the language, come to think of it.)

  • @jiriniewalra3434
    @jiriniewalra3434 2 ปีที่แล้ว

    Line 5: my_string is not mut and on line 5 is replace of substring. I though that it is not possible on const var.

    • @CunningBard
      @CunningBard 2 ปีที่แล้ว +2

      The reason why it worked is because `.replace` returns a value instead of changing the variable

  • @sgtnasty
    @sgtnasty 6 ปีที่แล้ว

    How come you dont have to implement Err(e) on the match my_string.chars().nth(4) ?

    • @anon04131993
      @anon04131993 6 ปีที่แล้ว +2

      that is because the nth method returns an Option enum not a Result

  • @sugiono2801
    @sugiono2801 5 ปีที่แล้ว

    how to join vector chars to one string?

    • @inx1819
      @inx1819 4 ปีที่แล้ว +1

      yourvector.to_iter().collect()

  • @Steve-3P0
    @Steve-3P0 6 ปีที่แล้ว +1

    Hi Domenic. Great videos. I'm trying to understand why you would do the last code snippet there (get char at index). That seems like a lot of code to print out the 4 element of a string. I know you explained that my_string[4] would work. I'm just trying to imagine scenarios where you would use this.

    • @dcode-software
      @dcode-software  6 ปีที่แล้ว +2

      Hey Steve, thanks mate :) - with that code snippet, I was simply demonstrating the "safe" way to do it. I've noticed the Rust community tends to really encourage safe code like this and so I thought it would be a good idea to demonstrate that. After doing a bit of research it looks like you can't actually use array notation in Rust to get characters at a particular index.