Mavzu: satrlar va kengaytirilgan belgilar


Satr qismini alishtirish funksiyasi


Download 71.88 Kb.
bet25/31
Sana25.11.2021
Hajmi71.88 Kb.
#177287
1   ...   21   22   23   24   25   26   27   28   ...   31
Bog'liq
10- Amaliyot

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


Download 71.88 Kb.

Do'stlaringiz bilan baham:
1   ...   21   22   23   24   25   26   27   28   ...   31




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling