In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article editor for you a detailed introduction of "C++ string commonly used to intercept string methods are what", detailed content, clear steps, details handled properly, I hope that this "C++ string commonly used to intercept string methods is what" article can help you solve doubts, the following slowly deepen along with the editor's ideas to learn new knowledge bar.
There are many common ways for string to intercept strings, but the combination of the following two methods can basically meet the requirements:
Find (string strSub, npos)
Find_last_of (string strSub, npos)
Where strSub is the substring you need to find, and npos is the starting position for finding. Find the location where the substring first appears, otherwise return-1
Note:
(1) the npos of find_last_of is the position to be searched from the end.
(2) the strsub (npos,size) function used below, where npos is the start position and size is the intercepted size
Example 1: directly find out whether there is a string in the string (return "2")
Std::string strPath = "E:\\ data\\ 2018\ 2000 coordinate system\\ a.shp" int a = 0; if (strPath.find ("2018") = = std::string::npos) {a = 1;} else {a = 2;} return a
Example 2: find a string of a string (return "E:")
Std::string strPath = "E:\\ data\\ 2018\ 2000 coordinate system\\ a.shp" int nPos = strPath.find ("\\"); if (nPos! =-1) {strPath = strPath.substr (0, nPos);} return strPath
Example 3: find the string between two substrings in a string (return "2000 coordinate system")
Std::string strPath = "E:\\ data\\ 2018\ 2000 coordinate system\\ a.shp" std::string::size_type nPos1 = std::string::npos;std::string::size_type nPos2 = std::string::npos;nPos1 = strPath.find_last_of ("\\"); nPos2 = strPath.find_last_of ("\\", nPos1-1) If (nPos1! =-1 & & npos2! =-1) {strPath = strPath.substr (nPos2 + 1, nPos1-nPos2-1);} return strPath
Improve: recursively get subdirectories in pathnames
/ / get the subdirectories in the pathname: strPath is the pathname, strSubPath is the output subdirectory, and nSearch is the level retrieved from the tail forward (default is level 1) bool _ GetSubPath (std::string& strPath,std::string& strSubPath, int nSearch) {if (- 1 = = nSearch | | strPath.empty ()) return false; std::string::size_type nPos1 = std::string::npos NPos1 = strPath.find_last_of ("\\"); if (nPos1! =-1) {strSubPath = strPath.substr (nPos1 + 1, strPath.length ()-nPos1); int nNewSearch = nSearch > 1? NSearch-1:-1; _ GetSubPath (strPath.substr (0, nPos1), strSubPath, nNewSearch);} return true;} int main () {std::string strPath = "E:\\ data\\ 2018\\ 2000 coordinate system\\ a.shp"; std::string strSubPath = ""; if (_ GetSubPath (strPath, strSubPath, 1) {printf ("return 'a.shp'") } if (_ GetSubPath (strPath, strSubPath, 2) {printf ("return '2000 coordinate system'");}} read this, this article "what is the common method of intercepting strings in string in C++" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it. If you want to know more about the article, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.