Shell基礎學習 字串

2021-09-24 10:14:55 字數 1178 閱讀 8150

str1=hello

str2=

'hello'

str3=

"hello"

$
直接將兩個字串放在一起即可:

str1=hello

str2=shell

str3=

$str1

$str2

str4=

"$str1

$str2"

str5=

"$:$"

(1)從左開始計數,擷取方向從左往右(從0開始計數,string是被擷取的字串,start是開始擷取的位置,length是擷取的長度)

$
(2)從右開始計數,擷取方向從左往右(從1開始計數,string是被擷取的字串,start是開始擷取的位置,length是擷取的長度)

$
#!/bin/bash

#字串的定義

str1=hello

str2=

'hello world'

str3=

"hello shell!"

#字串長度的獲取

echo str1:$

echo str2:$

echo str3:$

#字串的拼接

str4=

$str1

$str2

str5=

"$str1

$str2"

str6=

"$:$"

echo str4:$str4

echo str5:$str5

echo str6:$str6

#字串的擷取

str7=

$str8=

$echo str7:$str7

echo str8:$str8

str1:5

str2:11

str3:12

str4:hellohello world

str5:hellohello world

str6:hello:hello world

str7:ello

str8:llo s

c 基礎學習 字串處理

一 常用比較字串 1.string1.equals string2 比較string1和string2是否相同 區分大小寫 tolower 將字串轉換為小寫 toupper 將字串轉換為大寫 2.string1.compareto string2 string1等於string2 返回0,strin...

PHP基礎學習 字串操作

1.單引號和雙引號的區別 在php中,字串的定義可以使用英文單引號 也可以使用英文雙引號 str hello echo str is str 執行結果 str is hello echo str is str 執行結果 str is str 單引號不解析變數 2.字串的連線 用英文的點好.來連線兩個...

python基礎學習字串操作

常用的字串操作 somestring.capitalize 首字母大寫,不需要引數 somestring.lower 將字母轉換為小寫 somestring.upper 將字母轉換為大寫 somestring.count 統計引數出現的次數 somestring.find 查詢引數的索引 somes...