-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.rb
More file actions
executable file
·47 lines (32 loc) · 862 Bytes
/
string.rb
File metadata and controls
executable file
·47 lines (32 loc) · 862 Bytes
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env ruby
# -*- coding: UTF-8 -*-
$KCODE = "u"
#双引号标记的字符串允许替换和使用反斜线符号,单引号标记的字符串不允许替换,且只允许使用 \\ 和 \' 两个反斜线符号
puts 'escape string "\\"\n'
puts "escape string '\\'\n"
puts 'that\'s right'
puts "乘法: #{2*2*2}"
name = "jack"
puts "hello, #{name}"
puts %Q{in %Q like "" hello #{name}}
puts %q{in %q like '' test #{name}}
puts name.upcase
puts name.upcase.downcase
puts "A" * 10
test = "你 this is a test string"
# [start, length]
puts test[10, 10]
puts test[0]
# [start..end]
puts test[1..5]
puts "#{test.split(" ")}"
puts name.eql?("jack")
puts test.dump
puts "%s %s" % ["hello", name]
puts " 123".to_i
puts " 123.44".to_f
# replace
puts " name ".tr("name", "jack")
# reverse case
puts " HELLO jack".swapcase
puts " fsagsa ".strip