Satr qismini alishtirish funksiyasi.
aqiruvchi satrni qismini o‘rniga boshqa sartning qismini qo‘yish uchun kuyidagi funktsiyalar bilan foydlanish mumkin:
replace (unsigned int pos1, unsigned int n1, const string &str);
replace (unsigned int pos1, unsigned int n1, const string & str,unsigned int pos2,unsigned int n2);
replace (unsigned int pos1, unsigned int n1,const char *str, int n).
Bu fuksiyalar insert kabi ishlaydi , faqat chaqiruvchi satrda ko‘rsatilgan o‘rnidan n belgini o‘rniga str satr qismini qo‘yadi. Misol
char * sc=”0123456789”; // sc=”0123456789” satr kiritiladi
unsigned int i=3,j=2;
string s1,s,s2;
s2=sc; s1=”misollar”; s=”xyz”; // s2=”0123456789”
s2.replace(i,j,“abcdef”); // s2=”012abcdef 56789”
s1.replace(i-1,j+1,s2,4,5); // s1=”mi45678lar”
s.replace(i-2,j+2,sc,5); // s=”x012345”
Ikki satrni qiymatlarini to‘liq almashtirish uchun
swap(string &str); funktsiya ishlatiladi. Masalan
string s1,s,s2;
s1=”01234”;
s2=”98765432”;
s1.swap(s2) ; // s2=”01234” s1=”98765432” ~ s=s1;s1=s2;s2=s1
Do'stlaringiz bilan baham: |