Skip to content

Commit

Permalink
more on strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Himanshuxone committed Oct 31, 2016
1 parent d175dbf commit 36f1c55
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package main
import(
"fmt"
"strings"
"sort"
)

func main() {
Expand All @@ -24,4 +25,25 @@ func main() {
// here replace "l" character with "x" starting with third index
fmt.Println(strings.Replace(sampleString, "l", "x", 3))

// create a csv list of values to join and apply more string operations
csvString := "1,2,3,4,5"

// split the string from comma
fmt.Println( strings.Split( csvString, "," ) )

// create an array of string type

listOfLetters := []string{"c","b","a"}

// sort the liost of letters
sort.Strings(listOfLetters)
fmt.Println(listOfLetters)

// join the letters to using comma
fmt.Println(strings.Join(listOfLetters, ","))

// create a list of leetrs by joining using comma
listOfNums := strings.Join([]string{"1","2","3"}, ",")
fmt.Println(listOfNums)

}

0 comments on commit 36f1c55

Please sign in to comment.