วิธีใช้ charAt
charAt คือการ Access เข้าไปใน string แบบ array (string คือ array of char)
ถ้าใน C++ เราใช้แบบนี้ได้เลย
string str
str = “0123456789″;
printf(“%c”,str[0]);
แต่ถ้าเป็น Javascript ต้องใช้แบบนี้
var str;
str = “0123456789″;
print(str.charAt[0]);
วิชีการใช้ length ใช้สำหรับหาความยาว string อันนี้ใช้เหมือนภาษาอื่น คือ .length ได้เลย
การเพิ่ม method เข้าไปใน Obj ของ Javascript
จากตัวอย่างจะเป็นการ trim
String.prototype.trim = function () { return this.replace(/^\s*/, "").replace(/\s*$/, ""); } var str; str = "123456789 "; str.trim();
อ้างอิง
: http://www.quirksmode.org/js/strings.html
: http://www.delphifaq.com/faq/f1031.shtml
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
| « Jun | ||||||
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | 30 | ||
RSS feed for comments on this post · TrackBack URI
Leave a reply