สตริงและข้อความ
จัดเก็บและรวมค่าข้อความ
สตริงและข้อความ เป็นบทเรียน Mojo Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Mojo Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Mojo Academy มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
Text Is a String
Any sequence of characters, like a name or a message, is a String. It is how programs hold human-readable text. 💬
Make a String
Wrap text in double quotes to create a String, then store it in a var so you can reuse the text later.
var name = "Ada"Single or Double Quotes
Mojo accepts both quote styles. Pick the one that lets your text stay clean, like single quotes around a phrase with a quote inside.
var word = 'hello'Joining Text with +
Put two Strings together using +. This is called concatenation and it builds a longer string from pieces.
var greeting = "Hi, " + nameMind the Spaces
Concatenation glues text exactly as written. Add a space inside a String so words do not collide when joined.
var full = "Ada" + " " + "Lovelace"Printing Text
print sends a String to the screen. It is your quickest way to see what a String currently holds.
print("Hello, world")Empty and Long Strings
A String can be empty ("") or hold a whole sentence. Length is up to you; the type stays the same either way.
var blank = ""Numbers Are Not Text
"42" is a String, while 42 is an Int. They look alike but behave differently, so keep text and numbers distinct.
var label = "42"Turning a Number into Text
To join a number into a message, convert it with String first so the + has two strings to combine.
var msg = "Score: " + String(score)Strings Describe Your Program
Labels, prompts, and messages are all Strings. Clear text makes your output friendly for the person reading it.
Text Powers Communication
From greetings to error messages, Strings carry meaning to users. Mastering text is half of writing useful programs.
Quick Check
You have a number in score and want to put it inside a text message. What do you do first?
Recap
A String holds text in quotes, joins with +, and prints to the screen. Convert numbers to String before mixing them in. 🎯
คำถามที่พบบ่อย
บทเรียน “สตริงและข้อความ” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “สตริงและข้อความ” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Mojo Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Mojo Academy มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “สตริงและข้อความ”
จัดเก็บและรวมค่าข้อความ คุณปฏิบัติ Mojo Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Mojo Academy หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Mojo Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน
บทเรียน “สตริงและข้อความ” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Mojo Academy นี้ได้ไหม
ได้ บทเรียน Mojo Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ