如何比较golang中的两个版本号字符串 [英] How to compare two version number strings in golang
本文介绍了如何比较golang中的两个版本号字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
a:=1.05 .00.0156
b:=1.0.221.9289
我想比较哪一个是大。如何在golang中做到这一点?
解决方案
将1.05.00.0156转换为0001+0005+0000+0156 int64。
$ b 将1.0.221.9289转换为0001+0000+0221+9289,然后转换为int64。
$ b
比较两个int64值。
I have two strings (they are actually version numbers and they could be any version numbers)
a := "1.05.00.0156"
b := "1.0.221.9289"
I want to compare which one is bigger. How to do it in golang?
解决方案
Convert "1.05.00.0156" to "0001"+"0005"+"0000"+"0156", then to int64.
Convert "1.0.221.9289" to "0001"+"0000"+"0221"+"9289", then to int64.
Compare the two int64 values.
Try it on the Go playground
这篇关于如何比较golang中的两个版本号字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文