Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8315341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:06:38+00:00 2026-06-08T21:06:38+00:00

Spent several hours trying to find a solution to the ‘simple’ problem of converting

  • 0

Spent several hours trying to find a solution to the ‘simple’ problem of converting a string of digits to an array of single digit integers in Go. Tried many different approaches, but always ran into a problem. Here is the last one tried. It builds, but gives index out of range at runtime, on the line indicated. There will probably be a few AHs that will mark me down for asking stupid questions, but I couldn’t find a solution in the first 50 results of multiple Google searches. So come on dude, mark me down, you’re the man. To the other 99%: Thanks for your patience and help.

package main
import (
    "fmt"
    "strconv"
    "strings"
    )
func main() {
    s := "876567747896354336739443262"
    var dstr []string = strings.SplitAfterN(s,"",len(s))
    var dint []int
    for i := 0; i < len(s); i++ {
        dint[i], _ = strconv.Atoi(dstr[i]) //index out of range at runtime
        fmt.Printf("dstr[%v] is: %s\n", i, dstr[i])
        fmt.Printf("dint[%v] is: %v\n", i, dint[i])
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T21:06:40+00:00Added an answer on June 8, 2026 at 9:06 pm

    Here is the answer. Morphiax showed me the error in my ways. Thanks dude, appreciated. It turns out that this is wrong: var dint []int . I should have given the size when creating the array, when not initializing it: var dint [27]int . Here’s full code again:

    package main
    import (
        "fmt"
        "strconv"
        "strings"
        )
    func main() {
        s := "876567747896354336739443262"
        var dstr []string = strings.SplitAfterN(s,"",len(s))
        var dint [27]int
        for i := 0; i < len(s); i++ {
            dint[i], _ = strconv.Atoi(dstr[i]) 
            fmt.Printf("dstr[%v] is: %s\n", i, dstr[i])
            fmt.Printf("dint[%v] is: %v\n", i, dint[i])
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I spent several hours reading through docs and forums, trying to find a solution
I have spent several hours trying to find a means of writing a cross
This afternoon I spent several hours trying to find a bug in my custom
I hope someone can help me as I've already spent several hours trying to
I have now spent several hours trying to figure this out. I have this
I have spent the last several hours trying to get this to work and
I just spent several hours of my life debugging this problem. I'm documenting it
I've spent several hours trying to install MySQLdb (the Python library) on Mac OS
I've spent several hours over the past few days trying to get PostgreSQL to
I'm kind of new to JAXB and validation, and have spent several hours trying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.