java,string,startWith or prefix predicate,in c++,for copy
2012-01-06 12:44
381 查看
一些工具
C++ std::string --- 你可能不知道的一些用法
ref1
策略1 use boost lib
策略2 区间匹配
Use
Pass in the shorter string as the first iterator range and the longer as the second iterator range. The return is a pair of iterators, the first is the iterator in the first range and the second, in the second rage. If the first is end of the first range,
then you know the the short string is the prefix of the longer string e.g.
C++ std::string --- 你可能不知道的一些用法
ref1
策略1 use boost lib
#include <boost/algorithm/string/predicate.hpp> if (boost::starts_with(argv[1], "--foo="))
策略2 区间匹配
Using STL this could look like: std::string prefix = "--foo="; std::string arg = argv[1]; if (std::equal(prefix.begin(), prefix.end(), arg.begin())) { std::istringstream iss(arg.substr(prefix.size())); iss >> foo_value; }策略3 截取匹配
Code I use myself: std::string prefix = "-param="; std::string argument = arg[1]; if(argument.substr(0, prefix.size()) == prefix) { std::string argumentValue = argument.substr(prefix.size(), argument.size()); }策略4
Use
std::mismatch.
Pass in the shorter string as the first iterator range and the longer as the second iterator range. The return is a pair of iterators, the first is the iterator in the first range and the second, in the second rage. If the first is end of the first range,
then you know the the short string is the prefix of the longer string e.g.
std::string foo("foo"); // 甲 std::string foobar("foobar"); // 甲乙 auto res = std::mismatch(foo.begin(), foo.end(), foobar.begin()); if (res.first == foo.end()) { // foo is a prefix of foobar. } // for short std::mismatch(s1.begin(),s1.end(),s2.begin()).first==s1.end()
相关文章推荐
- The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this ap
- Java - Why String is Immutable or Final in Java
- exception http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
- Why String is immutable or final in Java
- Get number from string with regular expression in java
- This absolute uri http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
- HTTP Status 500 - The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
- Err:The "." operator was supplied with an index value of type "java.lang.String" to be applied to a List or array
- jstl学习常见错误一: The absolute uri: http://java.sun.com/jst/core cannot be resolved in either web.xml or the jar files deployed with
- Why String is Immutable or Final in Java
- Why String is immutable or final in Java
- HTTP Status 500 - The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
- IDEA错误:Failed to start end point associated with ProtocolHandler [http-nio-9999] java.net.BindException: Address already in use: bind
- A context path must either be an empty string or start with a '/' and do not end with a '/' 问题解决方法
- tomcat 7 WARNING: A context path must either be an empty string or start with a '/' and do not end with a '/'. The path [/] does not meet these criteria and has been changed to []
- There is no getter for property named 'column' in 'class java.lang.String'] with root cause
- IDEA 编译错误:java: try-with-resources is not supported in -source 1.6 (use -source 7 or higher to enable try-with-resources)
- 关于There is no getter for property named 'mohuname' in 'class java.lang.String'] with root cause问题
- Why String is immutable or final in Java
- The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application的解决办法