標題:
[6/8 作業4] replace() 函式
[打印本頁]
作者:
tonyh
時間:
2024-6-8 11:40
標題:
[6/8 作業4] replace() 函式
試以 replace() 函式,將字串中的目標對象以特定字串(或字元)取代。
<string> 標頭檔所提供的 replace() 函式可將字串中特定位置及長度的字串,以另一個字串取代;而 <algorithm> 標頭檔所提供的 replace() 函式可將字串中所有的特定字元,以另一個字元取代。
#include<iostream>
#include<cstdlib>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
string str1="honolulu";
cout<<str1.replace(1,3,"a")<<endl; //halulu
string str2="honolulu";
cout<<str2.replace(str2.find("u"),1,"a")<<endl; //honolalu
string str3="honolulu";
replace(str3.begin(),str3.end(),'u','a');
cout<<str3<<endl; //honolala
system("pause");
return 0;
}
複製代碼
作者:
邱奕倫
時間:
2024-6-9 20:54
#include<iostream>
#include<cstdlib>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
string str1="honolulu";
cout<<str1.replace(1,3,"a")<<endl; //halulu
string str2="honolulu";
cout<<str2.replace(str2.find("u"),1,"a")<<endl; //honolalu
string str3="honolulu";
replace(str3.begin(),str3.end(),'u','a');
cout<<str3<<endl; //honolala
system("pause");
return 0;
}
複製代碼
作者:
張仲言
時間:
2024-6-10 10:32
#include<iostream>
#include<cstdlib>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
string str1="honolulu";
cout<<str1.replace(1,3,"a")<<endl; //halulu
string str2="honolulu";
cout<<str2.replace(str2.find("u"),1,"a")<<endl; //honolalu
string str3="honolulu";
replace(str3.begin(),str3.end(),'u','a');
cout<<str3<<endl; //honolala
system("pause");
return 0;
}
複製代碼
作者:
陳煒翰
時間:
2024-6-10 16:28
#include<iostream>
#include<cstdlib>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
string str1="honolulu";
cout<<str1.replace(1,3,"a")<<endl; //halulu
string str2="honolulu";
cout<<str2.replace(str2.find("u"),1,"a")<<endl; //honolalu
string str3="honolulu";
replace(str3.begin(),str3.end(),'u','a');
cout<<str3<<endl; //honolala
system("pause");
return 0;
}
複製代碼
作者:
廖和風
時間:
2024-6-11 19:46
#include<iostream>
#include<cstdlib>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
string str1="honolulu";
cout<<str1.replace(1,3,"a")<<endl;
string str2="honolulu";
cout<<str2.replace(str2.find("u"),1,"a")<<endl;
string str3="honolulu";
replace(str3.begin(),str3.end(),'u','a');
cout<<str3<<endl;
system("pause");
return 0;
}
複製代碼
作者:
黃彥綺
時間:
2024-6-12 21:40
#include<iostream>
#include<cstdlib>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
string str1="honolulu";
cout<<str1.replace(1,3,"a")<<endl;
string str2="honolulu";
cout<<str2.replace(str2.find("u"),1,"a")<<endl;
string str3="honolulu";
replace(str3.begin(),str3.end(),'u','a');
cout<<str3<<endl;
system("pause");
return 0;
}
複製代碼
作者:
林宜靜
時間:
2024-6-13 22:26
#include<bits/stdc++.h>
using namespace std;
int main()
{
string str1="honolulu";
cout<<str1.replace(1,3,"a")<<endl;
string str2="honolulu";
cout<<str2.replace(str2.find("u"),1,"a")<<endl;
string str3="honolulu";
replace(str3.begin(),str3.end(),'u','a');
cout<<str3<<endl;
system("pause");
return 0;
}
複製代碼
作者:
曾湘鋆
時間:
2024-6-14 22:18
#include<iostream>
#include<cstdlib>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
string str1="honolulu";
cout<<str1.replace(1,3,"a")<<endl;
string str2="honolulu";
cout<<str2.replace(str2.find("u"),1,"a")<<endl;
string str3="honolulu";
replace(str3.begin(),str3.end(),'u','a');
cout<<str3<<endl;
system("pause");
return 0;
}
複製代碼
作者:
陳祈安
時間:
2024-6-14 23:59
#include<iostream>
#include<cstdlib>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
string str1="honolulu";
cout<<str1.replace(1,3,"a")<<endl;
string str2="honolulu";
cout<<str2.replace(str2.find("u"),1,"a")<<endl;
string str3="honolulu";
replace(str3.begin(),str3.end(),'u','a');
cout<<str3<<endl;
system("pause");
return 0;
}
複製代碼
作者:
邱思博
時間:
2024-6-15 07:43
#include<bits/strc++.h>
using namespace std;
int main()
{
string str1="honolulu";
cout<<str1.replace(1,3,"a")<<endl;
string str2="honolulu";
cout<<str2.replace(str2.find("u"),1,"a")<<endl;
string str3="honolulu";
replace(str3.begin(),str3.end(),'u','a');
cout<<str3<<endl;
system("pause");
return 0;
}
複製代碼
作者:
吳睿晏
時間:
2024-6-15 08:59
#include<bits/stdc++.h>
using namespace std;
int main()
{
string str1="honolulu";
cout<<str1.replace(1,3,"a")<<endl;
string str2="honolulu";
cout<<str2.replace(str2.find("u"),1,"a")<<endl;
string str3="honolulu";
replace(str3.begin(),str3.end(),'u','a');
cout<<str3<<endl;
system("pause");
return 0;
}
複製代碼
作者:
鄧維成
時間:
2024-6-15 09:58
本帖最後由 鄧維成 於 2024-6-15 10:25 編輯
#include<iostream>
#include<cstdlib>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
string str1="honolulu";
cout<<str1.replace(1,3,"a")<<endl; //halulu
string str2="honolulu";
cout<<str2.replace(str2.find("u"),1,"a")<<endl; //honolalu
string str3="honolulu";
replace(str3.begin(),str3.end(),'u','a');
cout<<str3<<endl; //honolalaaa
system("pause");
return 0;
}
複製代碼
作者:
林弈呈
時間:
2024-6-15 10:03
#include<iostream>
#include<cstdlib>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
string str1="honolulu";
cout<<str1.replace(1,3,"a")<<endl; //halulu
string str2="honolulu";
cout<<str2.replace(str2.find("u"),1,"a")<<endl; //honolalu
string str3="honolulu";
replace(str3.begin(),str3.end(),'u','a');
cout<<str3<<endl; //honolala
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2