Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save TheBraveByte/6f46b0b2c68bd8c55ab31ed85441e590 to your computer and use it in GitHub Desktop.
Save TheBraveByte/6f46b0b2c68bd8c55ab31ed85441e590 to your computer and use it in GitHub Desktop.

Revisions

  1. TheBraveByte created this gist Apr 23, 2022.
    44 changes: 44 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@

    import (
    "bufio"
    "fmt"
    "io"
    "os"
    "strings"
    )

    func ReadLine(reader *bufio.Reader) string {
    str, _, err := reader.ReadLine()
    if err == io.EOF {
    return ""
    }
    return strings.TrimRight(string(str), "\r\n")
    }
    func EvenOddIndex() {
    fmt.Println("Enter a string value (2<= string <=10000) : ")
    reader := bufio.NewReader(os.Stdin)
    str := strings.TrimSpace(ReadLine(reader))
    switch {
    case len(str) == 1:
    fmt.Print()
    break
    case len(str) > 1:
    evenIndex := ""
    oddIndex := ""
    for i, v := range str {
    if i%2 == 0 || i == 0 {
    evenIndex = evenIndex + string(v)
    } else if i%2 >= 1 {
    oddIndex = oddIndex + string(v)
    }
    }
    //fmt.Println("The characters in even index : ", evenIndex)
    //fmt.Println("The characters in odd index : ", oddIndex)
    fmt.Println(evenIndex, oddIndex)
    break

    default:
    fmt.Println("Input value less than 1")

    }
    }