記事更新日: 2018年06月05日

文字列に文字を追加
- Append char to strings.

KITASHIRAKAWA_Chiyuri

文字列に 文字を追加しようぜ☆
- Let's append a string to a string.

目次 - Table of contents.

戻る - back

シー☆ - C.

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'}
OKAZAKI_Yumemi

大変ねぇ。
- It is hard work.

戻る - back

シープラプラ☆ - C++.

#include <stdio.h>
#include <string>

std::string s1 = "";
std::string s2 = "Raion";
std::string buf = s1 + s2;
OKAZAKI_Yumemi

足し算と同じねぇ。
- It is the same as addition.

2015年11月25日「文字列で学ぶC++入門」@7shi

戻る - back

シーシャープ☆ - C#.

string str = "";
str += "Raion";

// または

StringBuilder sb = new StringBuilder();
sb.Append("Raion");
string str2 = sb.ToString();
KIFUWARABE

足し算でも追加できるぜ☆
- Can add by addition.

2003/05/23「文字列を連結するには?」@IT

戻る - back

ゴ☆ - Go.

s := "Raio";
c := 'n';
fmt.Println(s + string(c));
KITASHIRAKAWA_Chiyuri

こういうことかだぜ☆?
- I mean something like this?

2016-10-28「How to append a character to a string in Golang?」stack overflow

戻る - back

ジャバ☆ - Java.

new StringBuilder().append("Raio")
                   .append("n")
                   .toString();
KITASHIRAKAWA_Chiyuri

これでいいのだろうか☆?
- Is this OK?

2013-01-21「Append a single character to a string or char array in java?」stack overflow

戻る - back

ジャバスクリプト☆ - Java script.

var str = "Raio";
str += "n";
KITASHIRAKAWA_Chiyuri

足し算しようぜ☆
- Let's add?

「JavaScript String charAt() Method」w3schools.com

戻る - back

ルア☆ - Lua.

str = "Raio"
str = str .. "n"
KITASHIRAKAWA_Chiyuri

これでくっつくぜ☆
- This will stick.

2009-09-10「Concatenation of strings in Lua」stack overflow
戻る - back

パール☆ - Perl.

$str1 = 'io'; 
$str2 = 'Ra' . $str1 . 'n'; 
KITASHIRAKAWA_Chiyuri

これでいいのかなあ☆?
- I wonder if this is OK?

「What is the shortest way to convert string characters into an array of characters in Perl?」stack overflow
戻る - back

ピーエイチピー☆ - PHP.

$str1 = "Ra";
$str2 = $str1 . "ion";
KITASHIRAKAWA_Chiyuri

こんなんかなあ☆?
- I wonder if this?

「String Operators」php
戻る - back

パイソン☆ - Python.

print 'Ra' + 'ion'
KITASHIRAKAWA_Chiyuri

うーん、わかんないぜ☆
- Well, I do not understand.

Dec. 09, 2012「String Concatenation and Formatting」Python For Beginners
戻る - back

ルビー☆ - Ruby.

str1 = "Rai"
str1 += "on"
KITASHIRAKAWA_Chiyuri

これで合ってるのかだぜ☆?
- Does this match?

April 2007「Appending to a string」RUBY FLEEBIE
戻る - back

ラスト☆ - Rust.

let mut str = String::from("Raio");
str.push('n');
KITASHIRAKAWA_Chiyuri

多分こう☆
- Probably.

2016-06-17「How to concatenate a char onto a string in Rust?」stack overflow