To display contact numbers separated by commas instead of line breaks, you can use the result.append
method to concatenate each phone number along with a comma. Here’s how you can modify your code:
javaString displayName = contact.getPhone(0);
result.append(displayName); // Append the first phone number without a comma
// Loop through the rest of the phone numbers and append them with a comma
for (int i = 1; i < contact.getPhoneCount(); i++) {
result.append("," + contact.getPhone(i));
}
// Append a newline at the end if needed
result.append("\n");
This code will concatenate all phone numbers with commas between them, and a newline at the end if you still need it.
مقالات ذات صلة
-
مشكلة أبعاد المصفوفة في C++28/03/2024
المزيد من المعلومات
لعرض أرقام الاتصال مفصولة بفواصل، يمكنك استخدام حلقة for
للانتقال عبر جميع أرقام الاتصال ودمجها في نص واحد مع وضع فاصلة بين كل رقم. هناك العديد من الطرق لتحقيق ذلك، وإليك كيف يمكن تعديل الكود:
javaString displayName = contact.getPhone(0);
result.append(displayName); // إضافة الرقم الأول بدون فاصلة
// حلقة لدمج باقي الأرقام مع وضع فاصلة بين كل رقم
for (int i = 1; i < contact.getPhoneCount(); i++) {
result.append("," + contact.getPhone(i));
}
// إضافة فاصلة جديدة في نهاية النص إذا لزم الأمر
result.append("\n");
هذا الكود سيقوم بدمج جميع أرقام الهواتف بفواصل بينها، وفاصلة جديدة في نهاية النص إذا كان ذلك مطلوبًا.