64,647
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str="12345679.txt"; // -> 123....txt(截取了前3个,后面用省略号代替 +.wav)";
size_t index=str.find_first_of("."); //找到.的位置索引
str.replace(index-5,index-2,"....");
cout<<str<<endl;
system("pause");
return 0;
}
#include <iostream>
#include <string>
using namespace std;
#define LEN 3
int main()
{
string s = "123456.test.txt";
string res = "";
size_t i = s.find_last_of(".");
string sub = "";
string head = s;
if (i != string::npos)
{
sub = s.substr(i, s.length()-i);
head = s.substr(0, i);
}
if (head.length() > LEN)
{
head = head.substr(0,LEN);
head += "...";
}
res = head + sub;
cout << res << endl;
return 0;
}