Skip to content

Commit 75f04a4

Browse files
authored
Merge pull request #106 from devlights/issue-#104
Add string to rune slice example ( close #104 )
2 parents 31b319c + 7750fb7 commit 75f04a4

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

basic/string_/string01.go renamed to basic/string_/string_rune_rawstring.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package string_
22

33
import "fmt"
44

5-
// Go言語における 文字と文字列とRaw文字列について
6-
func String01() error {
5+
// StringRuneRawStringは、Go言語における 文字と文字列とRaw文字列についてのサンプルです
6+
func StringRuneRawString() error {
77
// string. 文字列
88
string1 := "こんにちは"
99

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package string_
2+
3+
import "fmt"
4+
5+
// StringToRuneSliceは、文字列とルーンスライスの遷移を表示するサンプルです
6+
func StringToRuneSlice() error {
7+
8+
// Go の 文字列 は、他の言語と同様に immutable となっている
9+
// なので、一度作成した文字列を変更することは出来ない
10+
// 変更したい場合は、新たな文字列を作って格納する必要がある
11+
s := "hello world"
12+
13+
// 文字列を runeスライス に変換
14+
r := []rune(s)
15+
16+
// 変更
17+
r[0] = 'H'
18+
19+
// 再度文字列へ
20+
s2 := string(r)
21+
22+
fmt.Printf("Before:\t%q\tAfter:\t%q\tRune:%v\n", s, s2, r)
23+
24+
return nil
25+
}

lib/mapping.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ func (m SampleMapping) MakeMapping() {
7272
m["slice_reverse"] = slice_.SliceReverse
7373
m["comment01"] = comments.Comment01
7474
m["closure01"] = closure.Closure01
75-
m["string01"] = string_.String01
75+
m["string_rune_rawstring"] = string_.StringRuneRawString
76+
m["string_to_runeslice"] = string_.StringToRuneSlice
7677
m["set01"] = sets.Set01
7778
m["set02"] = sets.Set02
7879
m["set03"] = sets.Set03

0 commit comments

Comments
 (0)