需要提取字符串中的最后一个数字,如“7.8.9.1.5.1.100” [英] Need to extract last figure after dot in a string like "7.8.9.1.5.1.100"
本文介绍了需要提取字符串中的最后一个数字,如“7.8.9.1.5.1.100”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要提取C ++字符串中最后一个点之后的最后一个数字,例如7.8.9.1.5.1.100,并将其存储在整数中。
strong>已添加:
此字符串也可以是7.8.9.1.5.1.1或7.8.9.1.5.1.0。
解决方案
code> std :: string 有一个
rfind()
方法;这将给你最后的。
从这里有一个简单的 substr()
得到字符串100
。 I need to extract last number after last dot in a C++ string like "7.8.9.1.5.1.100" and store it in an integer??
Added: This string could also be "7.8.9.1.5.1.1" or "7.8.9.1.5.1.0".
I would also like to validate that that its is exactly "7.8.9.1.5.1" before last dot.
解决方案
std::string
has a rfind()
method; that will give you the last .
From there it's a simple substr()
to get the string "100"
.
这篇关于需要提取字符串中的最后一个数字,如“7.8.9.1.5.1.100”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文