[Java]MessageFormat : insert values between single quotes
หลังจากได้แนะนำการใช้ การจัด Format Message ก็ใช้งานมาเรื่อยจนวันนี้ ติดปัญหาเล็กน้อยในการ ใช้ MessageFormat สำหรับ format ข้อความที่มีเครื่องหมาย ” (single quotes) เนื่องจากหลังจาก format แล้วเครื่องหมาย ” จะหายไปโดยปริยาย เช่น
String msg = "Hi, '{0}' this is {1}"; String val = MessageFormat.format(msg, "test", "xx"); System.out.println(val);
ข้อความที่ได้จะกลายเป็น Hi, test this is xx
ด้วยความช่วยเหลือจาก อ.google ก็พบวิธีแก้ไขดังนี้
String msg = "Hi, ''{0}'' this is {1}"; String val = MessageFormat.format(msg, "test", "xx"); System.out.println(val);
โดยการเพิ่ม ” ครอบ ” อีกทีหนึ่ง
ลอกมาจาก
Java MessageFormat – How can I insert values between single quotes?
No comments yet.