Comparing not equal length strings in Go -
when compare following not equal length strings in go, result of comparison not right. can help?
i := "1206410694" j := "128000000" fmt.println("result is", >= j, i, j ) the output is:
result false 1206410694 128000000 the reason because go char char comparison starting significant char. in case these strings represent numbers larger j. wonder if can explaining how not equal length strings compared in go.
the reason because go char char comparison starting significant char.
this correct.
if represent numbers, should compare them numbers. parse / convert them int before comparing:
ii, _ := strconv.atoi(i) ij, _ := strconv.atoi(j) edit: , yes, @jimb totally right. if not 100% sure conversion succeed, please not ignore errors.
Comments
Post a Comment