ทริคง่ายๆในการใช้ substring หรือ substr by dekunderkover
30
Sep0
Sep0
ความแตกต่างระหว่าง substring กับ substr มีความแตกต่างเพียงเล็กน้อย แต่ถ้าใช้ผิดเมื่อไหร่ ผลลัพธ์ที่ได้ออกมาแตกต่างกันมากเลยทีเดียว
เริ่มจากการที่เรามีค่า String ก่อน
var word:String = "Hello World, we come in peace."
เริ่มจากการใช้ substring กันก่อน
word.substring(6, 14); //output: World, w
และการใช้ substr
word.substr(6, 14); //output: World, we come
ความแตกต่างคือ
substring ตัดตัวหนังสือตั้งแต่ตัวที่ 6 จนถึงตัวที่ 14
substring(first letter, last letter);
substr ตัดตัวหนังสือตั้งแต่ตัวที่ 6 ถัดไป 14 ตัว
substr(first letter, length of word);
ไม่ยากเลยใช่มั้ย อย่าเผลอใช้ผิดก็แล้วกันนะ
Enjoy this article?
Consider subscribing to our RSS feed!
ไม่มีความเห็น
ยังไม่มีความเห็น