0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

文字列の一部を可変にする

Posted at

Androidのxmlで定義した一部の文字列を変更する方法をメモする。

<string name="name">%s文字以上で入力してください。</string>
val setNameMessage = getString(R.string.name, "7")
println(setNameMessage) // 7文字以上で入力してください。

変数を複数入れる場合はgetString()の第3、第4引数へと追加していく。

<string name="full_name">%s文字以上%s文字以下で入力してください。</string>
val setNameMessage = getString(R.string.full_name, "7", "20")
println(setNameMessage) // 7文字以上20文字以下で入力してください。

1$を追加すれば、引数の順番を変更することもできる。

<string name="full_name">%2$s文字以上%1$s文字以下で入力してください。</string>
val setNameMessage = getString(R.string.full_name, "25", "10")
println(setNameMessage) // 10文字以上25文字以下で入力してください

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?