我有两个字符串(它们实际上是版本号,可以是任何版本号)
a := "1.05.00.0156"
b := "1.0.221.9289"
我想比较哪个更大。在golang中怎么做?
最佳答案
Hashicorp 提供了一个不错的解决方案 - https://github.com/hashicorp/go-version
import github.com/hashicorp/go-version
v1, err := version.NewVersion("1.2")
v2, err := version.NewVersion("1.5+metadata")
// Comparison example. There is also GreaterThan, Equal, and just
// a simple Compare that returns an int allowing easy >=, <=, etc.
if v1.LessThan(v2) {
fmt.Printf("%s is less than %s", v1, v2)
}
关于go - 如何在golang中比较两个版本号字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18409373/