|
setup diary |
R | julia | ruby | python3 | |
繰返 | paste(rep("abc",3),collapse="") | "abc"^3 | "abc"*3 | "abc"*3 |
連結 | paste("abc","def",sep="") | "abc"*"def" | "abc"+"def" | "abc"+"def" |
結合 | paste(1:5,collapse=", ") | join(1:5,", ") | [*1..5]*", " | ", ".join(map(str,range(1,6))) |
取出 | substr("πℯ^2",2,2) | collect("πℯ^2")[2] | "πℯ^2"[1] | "πℯ^2"[1] |
部分 | substr("πℯ^2",2,3) | String(collect("πℯ^2")[2:3]) | "πℯ^2"[1..2] "πℯ^2"[1,2] | "πℯ^2"[1:3] |
文字数 | nchar("πℯ^2") | length("πℯ^2") | "πℯ^2".length "πℯ^2".size | len("πℯ^2") |
大文字 | toupper("This") | uppercase("This") | "This".upcase | "This".upper() |
小文字 | tolower("This") | lowercase("This") | "This".downcase | "This".lower() |
入れ替え | chartr("A-Za-z","a-zA-Z","This") | "This".swapcase | "This".swapcase() | |
埋込 | s="world" "Hello $(s)!" | s="world" "Hello #{s}!" | s="world" f"Hello {s}!" "Hello {}!".format(s) | |
書式 | sprintf("%d %s",3,"times") | using Printf;@sprintf("%d %s",3,"times") | sprintf("%d %s",3,"times") "%d %s"%[3,"times"] | "%d %s"%(3,"times") |
文字列 | as.character(123) | string(123) | 123.to_s | str(123) |
整数 | as.integer("1") | parse(Int,"1") | "1".to_i | int("1") |
浮動小数点 | as.numeric("1") | parse(Float64,"1") | "1".to_f | float("1") |
複素数 | as.complex("1+2i") | parse(Complex{Int},"1+2im") | "1+2i".to_c | complex("1+2j") |
コード変換 | utf8ToInt("A") | Int('A') | "A".ord | ord("A") |
文字変換 | intToUtf8(960) | Char(960) | 960.chr(Encoding::UTF_8) | chr(960) |
検索 | regexpr("[\\d\\.]+","pi=3.14",perl=TRUE) | match(r"[\d\.]+","pi=3.14") | "pi=3.14"=~/[\d\.]+/ | import re;re.search("[\d\.]+","pi=3.14") |
置換 | sub("(\\d)\\.",".\\1","pi=3.14") | replace("pi=3.14", r"(\d)\." => s".\1") | "pi=3.14".sub(/(\d)\./,'.\1') | import re;re.sub("(\d)\.",".\\1","pi=3.14") |
分割 | strsplit("1,2, 3",",\\s*")[[1]] | split("1,2, 3", r",\s*") | "1,2, 3".split(/,\s*/) | import re;re.split(",\s*","1,2, 3") |