Running a number of consecutive replacements on the same string

前端 未结 3 326
盖世英雄少女心
盖世英雄少女心 2021-01-12 08:43

I found this example for substring replacement:

use std::str;
let string = \"orange\";
let new_string = str::replace(string, \"or\", \"str\");
3条回答
  •  清酒与你
    2021-01-12 09:28

    There is no way in the standard library to do this; it’s a tricky thing to get right with a large number of variations on how you would go about doing it, depending on a number of factors. You would need to write such a function yourself.

提交回复
热议问题