And*_*owl 17
以下是如何在C++中执行此操作(当我回答时,问题被标记为C++):
#include <string>
#include <iostream>
std::string process(std::string const& s)
{
std::string::size_type pos = s.find('/');
if (pos != std::string::npos)
{
return s.substr(0, pos);
}
else
{
return s;
}
}
int main(){
std::string s = process("10.10.10.10/16");
std::cout << s;
}
Run Code Online (Sandbox Code Playgroud)
pmg*_*pmg 16
只需在斜线的位置放一个0
#include <string.h> /* for strchr() */
char address[] = "10.10.10.10/10";
char *p = strchr(address, '/');
if (!p) /* deal with error: / not present" */;
*p = 0;
Run Code Online (Sandbox Code Playgroud)
我不知道这是否适用于C++