Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12171

Remove leading digit from an uint in without parsing to string and back

$
0
0

I'm having a uint as 3123456, and I want to get 123456 as number (ideally uint), i.e. with the first digit stripped.I know I could parse it as a string, remove the leading character, and convert it back:

func (id *MyID) Scan(v any) (err error) {    asBytes, ok := v.([]byte)    ...    myDBNumber := binary.LittleEndian.Uint64(asBytes) // the field is of type BINARY in the db    myDBNumberStr := strconv.Itoa(int(myDBNumber))    myDBNumberWithoutPrefix, err := strconv.Atoi(myDBNumberStr[1:])    ...}

Since I'm using this logic in an sql.Scanner to parse IDs, I'm wondering whether there's a way where this parsing back and forward can be avoided, to improve the performance (or at least to compare the performance).


Viewing all articles
Browse latest Browse all 12171

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>