String handling · การจัดการสตริง
LENGTH counts characters
LENGTH(s)gives how many characters are in a string.
ความยาวนับจำนวนตัวอักษร
LENGTH(s)บอกจำนวนตัวอักษรในสตริง
OUTPUT LENGTH("hello") // → 5
UCASE and LCASE change case
UCASE(s)makes a string all CAPITALS.LCASE(s)makes it all lower case.
UCASE และ LCASE เปลี่ยนตัวพิมพ์
UCASE(s)ทำให้สตริงเป็นตัวพิมพ์ใหญ่ทั้งหมดLCASE(s)ทำให้เป็นตัวพิมพ์เล็กทั้งหมด
OUTPUT UCASE("abc") // → ABC
OUTPUT LCASE("HeLLo") // → hello
SUBSTRING takes part of a string
SUBSTRING(s, start, length)copies part of a string.- The first character is position 1 (not 0).
SUBSTRING ดึงส่วนหนึ่งของสตริง
SUBSTRING(s, start, length)คัดลอกส่วนหนึ่งของสตริง- ตัวแรกอยู่ในตำแหน่ง 1 (ไม่ใช่ 0)
OUTPUT SUBSTRING("Computer", 1, 4) // → Comp
Printing several values
OUTPUTtakes several values separated by commas and prints them one after another.- The 0478 pseudocode has no "join" operator — a comma is how you put values side by side.
การพิมพ์หลายค่า
OUTPUTรับหลายค่าที่แยกด้วย ลูกน้ำ แล้วพิมพ์เรียงกัน- รหัส伪代码 0478 ไม่มีออปレーター "join" — ลูกน้ำคือวิธีวางค่าข้างกัน
DECLARE Lives : INTEGER
Lives ← 3
OUTPUT "Cam", "bridge" // → Cambridge
OUTPUT "You have ", Lives, " lives left"
Common mistakes
- Learn the exam's function names:
LENGTH,SUBSTRING,UCASE,LCASE. - String positions in pseudocode often start at
1, not0.
ข้อผิดพลาดที่พบบ่อย
- เรียนชื่อฟังก์ชันในการสอบ:
LENGTH,SUBSTRING,UCASE,LCASE - ตำแหน่งของสตริงในรหัส伪代码 มักเริ่มที่
1ไม่ใช่0
Now you try
- Use the string functions above.
- Press Check answer to test it.
ลองดูเลย
- ใช้ฟังก์ชันสตริงด้านบน
- กด Check answer เพื่อทดสอบ
Read a word, then output how many characters it has with LENGTH. For input hello, output 5. · อ่านคำหนึ่งคำ, แล้วแสดงผลว่าคำนั้นมีตัวอักษรกี่ตัวโดยใช้ LENGTH สำหรับอินพุต hello, ผลลัพธ์ที่ได้คือ 5
Click Run to see the output here. · คลิก Run เพื่อดูผลลัพธ์ที่นี่
Read a word and output it in CAPITALS with UCASE. For input cat, output CAT. · อ่านคำและแสดงคำนั้นเป็นตัวพิมพ์ใหญ่โดยใช้ UCASE. สำหรับอินพุต cat, แสดงผล CAT
Click Run to see the output here. · คลิก Run เพื่อดูผลลัพธ์ที่นี่
Read a word and output its first 3 letters with SUBSTRING (start at 1, length 3). For input Computer, output Com. · อ่านคำและแสดง 3 ตัวอักษรแรก โดยใช้ SUBSTRING (เริ่มที่ 1, ความยาว 3) สำหรับอินพุต Computer, แสดงผล Com
Click Run to see the output here. · คลิก Run เพื่อดูผลลัพธ์ที่นี่