Agar siz nogahon bufferdagi satr uzunligini oshkor holda o’rnatishingizga
to’g’ri kelsa, setLength metodini ishlatishingiz mumkin.Agar sizdagi satr
uzunligining kattaroq sonni uzatsangiz bu metod yangi kengaygan satr oxirini
nol(0) kodli belgi bilan to’ldiradi sal keyinroq keltiriladigan setCharDemo
String Bufferidan bitta belgini charAt metodi yordamida ajratib olinadi.Boshqa
metod setCharAt satrning berilgan o’rniga(pozitsiyasiga) kerakli belgini yozishga
49
StringBuilder sb = new StringBuilder Hello");
Console.Write ("buffer before = " + sb);
Console.Write ("charAt(1) before = " + sb.charAt(1));
sb.setCharAt(1, 'i');
sb.setLength(2);
Console.Write ("buffer after = " + sb);
Console.Write ("charAt(1) after = " + sb.charAt(1));
} }
Ushbu dastur ishga tushirilganda olinadigan natija:
buffer before = Hello
charAt(1) before = e
buffer after = Hi
charAt(1) after = i
Do'stlaringiz bilan baham: