記事更新日: 2018年06月05日
文字列に 文字を追加しようぜ☆
- Let's append a string to a string.
char s[6] = {'\0'}; // {'\0', '\0', '\0', '\0', '\0', '\0'} strcat(s, "R"); // {'R', '\0', '\0', '\0', '\0', '\0'} strcat(s, "a"); // {'R', 'a', '\0', '\0', '\0', '\0'} strcat(s, "i"); // {'R', 'a', 'i', '\0', '\0', '\0'} strcat(s, "o"); // {'R', 'a', 'i', 'o', '\0', '\0'} strcat(s, "n"); // {'R', 'a', 'i', 'o', 'n', '\0'}
大変ねぇ。
- It is hard work.
#include <stdio.h> #include <string> std::string s1 = ""; std::string s2 = "Raion"; std::string buf = s1 + s2;
足し算と同じねぇ。
- It is the same as addition.
string str = ""; str += "Raion"; // または StringBuilder sb = new StringBuilder(); sb.Append("Raion"); string str2 = sb.ToString();
足し算でも追加できるぜ☆
- Can add by addition.
s := "Raio"; c := 'n'; fmt.Println(s + string(c));
こういうことかだぜ☆?
- I mean something like this?
2016-10-28「How to append a character to a string in Golang?」stack overflow
new StringBuilder().append("Raio") .append("n") .toString();
これでいいのだろうか☆?
- Is this OK?
2013-01-21「Append a single character to a string or char array in java?」stack overflow
var str = "Raio"; str += "n";
足し算しようぜ☆
- Let's add?
str = "Raio" str = str .. "n"
これでくっつくぜ☆
- This will stick.
$str1 = 'io'; $str2 = 'Ra' . $str1 . 'n';
これでいいのかなあ☆?
- I wonder if this is OK?
$str1 = "Ra"; $str2 = $str1 . "ion";
こんなんかなあ☆?
- I wonder if this?
print 'Ra' + 'ion'
うーん、わかんないぜ☆
- Well, I do not understand.
str1 = "Rai" str1 += "on"
これで合ってるのかだぜ☆?
- Does this match?
let mut str = String::from("Raio"); str.push('n');
多分こう☆
- Probably.