0

There is sp_std module, https://docs.rs/sp-std/3.0.0/sp_std/fmt/index.html

But using format! or string gives error:

 let vote_string = format!("{}-{}", account_string, phrase_string);

error: cannot find macro format in this scope

let phrase_string = String::from_utf8(phrase.clone()).unwrap();

^^^^^^ use of undeclared type String

Importing
use sp_std::string::String;
doesnot work.

Amiya Behera
  • 2,210
  • 19
  • 32
  • Does this answer your question? [How can I save string value on Substrate](https://stackoverflow.com/questions/63221904/how-can-i-save-string-value-on-substrate) – Shawn Tabrizi Apr 13 '21 at 12:31
  • No, its for storing strings as Vec, I need string functions like string concatenation, which is not possible using Vec – Amiya Behera Apr 13 '21 at 12:34
  • 3
    In general, you shouldn't be doing things like string manipulation in your runtime. It usually implies that you are not using your runtime correctly for critical consensus driven logic. However, to concatenate two strings as `Vec`, you simply extend one vec with the other. https://doc.rust-lang.org/std/vec/struct.Vec.html#method.append – Shawn Tabrizi Apr 13 '21 at 12:37
  • Does this answer your question? [Runtime Building: String not found in this scope](https://stackoverflow.com/questions/65348505/runtime-building-string-not-found-in-this-scope) – Nuke Apr 13 '21 at 17:59

1 Answers1

0

Shawn's answer in the comments above is best:

In general, you shouldn't be doing things like string manipulation in your runtime. It usually implies that you are not using your runtime correctly for critical consensus driven logic. However, to concatenate two strings as Vec, you simply extend one vec with the other. doc.rust-lang.org/std/vec/struct.Vec.html#method.append

For more explanation, see this stackoverflow post

Nuke
  • 1,032
  • 7
  • 13