Chapter 11: Strings


Replace sequence of characters with another sequence of characters


Download 0.83 Mb.
bet12/12
Sana18.12.2022
Hajmi0.83 Mb.
#1031312
1   ...   4   5   6   7   8   9   10   11   12
Bog'liq
dasturlsh string

Replace sequence of characters with another sequence of characters:
String replace(CharSequence target, CharSequence replacement)

Regex


Note: guruhlash $1 kabi guruhlarga murojaat qilish uchun $ belgisidan foydalanadi.
Replace all matches:



Section 11.15: Getting the length of a String


length

String obyektining uzunligini olish uchun undagi () usulini chaqiring. Uzunlik qatordagi UTF-16 kod birliklari (belgilar) soniga teng.

Live Demo on Ideone
Stringdagi belgi UTF-16 qiymatidir. Qiymatlari ≥ 0x1000 bo'lgan Unicode kod nuqtalari (masalan, ko'pchilik emojilar) ikkita belgi pozitsiyasidan foydalanadi. Stringdagi Unicode kod nuqtalari sonini hisoblash uchun, har bir kod nuqtasi UTF-16 belgilar qiymatiga mos kelishidan qat'i nazar, codePointCount usulidan foydalanishingiz mumkin:

You can also use a Stream of codepoints, as of Java 8:

Section 11.16: Getting the nth character in a String




charAt

Satrdagi n-belgini olish uchun satrda (n) ga qo'ng'iroq qiling, bu erda n - siz olishni istagan belgi indeksi

Izoh: n indeksi 0 dan boshlanadi, shuning uchun birinchi element n=0 da.

Section 11.17: Counting occurrences of a substring or character in a string


org.apache.commons.lang3.StringUtils dan countMatches usuli odatda Stringdagi pastki satr yoki belgilarning takrorlanishini hisoblash uchun ishlatiladi:

Aks holda, standart Java API bilan bir xil bo'lsa, siz Muntazam ifodalardan foydalanishingiz mumkin:


GoalKicker.com – Java® Notes for Professionals

Download 0.83 Mb.

Do'stlaringiz bilan baham:
1   ...   4   5   6   7   8   9   10   11   12




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