Javaالدالة getChars() في جافا
تعريفها
تنسخ أحرف الـ String الذي قام باستدعائها بداخل مصفوفة الأحرف التي نمررها لها مكان الباراميتر dst مع تحديد النطاق الذي نريد نسخه و المكان الذي نريد وضع الأحرف فيه.
بناؤها
public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
باراميترات
- مكان الباراميتر srcBegin نمرر رقم يمثل index أول حرف في الـ String تبدأ عملية النسخ من عنده.
- مكان الباراميتر srcEnd نمرر رقم يمثل index الحرف في الـ String الذي تتوقف عملية النسخ عنده.
- مكان الباراميتر dst نمرر المصفوفة التي ستتخزن فيها النسخة.
- مكان الباراميتر dstBegin نمرر رقم يمثل index أول حرف في المصفوفة تبدأ عملية اللصق عنده.
قيمة الإرجاع
لا ترجع قيمة.
مثال
public class Main {
public static void main(String[] args) {
String str = "welcome to harmash.com";
char[] arr = new char[str.length()];
str.getChars( 0, str.length(), arr, 0 );
System.out.print( "Copied value = ");
for(int i=0; i<arr.length; i++) {
System.out.print(arr[i]);
}
}
}
public class Main {
public static void main(String[] args) {
String str = "welcome to harmash.com";
char[] arr = new char[str.length()];
str.getChars( 0, str.length(), arr, 0 );
System.out.print( "Copied value = ");
for(int i=0; i<arr.length; i++) {
System.out.print(arr[i]);
}
}
}
سنحصل على النتيجة التالية عند التشغيل.
Copied value = welcome to harmash.com
Copied value = welcome to harmash.com