TechFree avatar

ស្វែងយល់ពី String នៅក្នុងភាសា Ruby

techfree

Published: 15 Jun 2018 › Updated: 15 Jun 2018ស្វែងយល់ពី String នៅក្នុងភាសា Ruby

ស្វែងយល់ពី String នៅក្នុងភាសា Ruby

ruby-string.jpg

Ruby ដំណើរការជាមួយ strings ដូចទិន្នន័យជាលេខដែរ។ ខ្សែអក្សរ (string) អាចប្រើជាមួយ double-quoted ( “… “) ឬ single-quoted ( ‘… ‘) ។

Double-quoted ( “… “) ឬ single-quoted ( ‘… ‘) មានផលប៉ះពាល់ផ្សេងគ្នានៅក្នុងករណីមួយចំនួន។ ខ្សែអក្សរ (string) double-quoted អនុញ្ញាតឱ្យតួអក្សរគេចផុតពីសញ្ញាទ្រេតឆ្វេង (backslash) ឈានមុខគេនិងការវាយតម្លៃនៃកន្សោមដែលបានប្រើសញ្ញា # {} ។ ខ្សែអក្សរ (string) single-quoted មិនធ្វើការបកប្រែទេ អ្វីដែលអ្នកឃើញគឺជាអ្វីដែលអ្នកទទួលបាន។

១) អាចប្រើ double-quoted ( “… “) ឬ single-quoted ( ‘… ‘) ប៉ុន្តែ ( ‘… ‘) គឺមានប្រសិទ្ធភាពជាង

puts "Hello World"

puts 'Hello World'

លទ្ធផល៖

Hello World

Hello World

២) ភ្ជាប់អក្សរ (string) បន្តគ្នា

puts 'I like' + ' Ruby'

លទ្ធផល៖

I like Ruby

៣) វិធីប្រើ ' នៅក្នុងstring

puts 'It\'s my Ruby'

លទ្ធផល៖

It's my Ruby

៤) ភ្ជាប់អក្សរ (string) បីដង

puts 'Hello' * 3

លទ្ធផល៖

HelloHelloHello

៥) កំណត់អថេរ

PI = 3.1416
puts PI

លទ្ធផល៖

3.1416

ឧទាហរណ៍ខាងក្រោមគឺយើងប្រើការភ្ជាប់អក្សរ (string) ដើម្បីទៅជាពាក្យ៖

ruby-string1.png

យើងបានលទ្ធផលដូចខាងក្រោម៖

ruby-string.png

ប្រភពដើម

Leave ស្វែងយល់ពី String នៅក្នុងភាសា Ruby to:

Written by

Read more #cambodia posts


Best Posts From TechFree

We have not curated any of techfree's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From TechFree