字串包含關係判斷
1、利用grep查詢
str1="ABC"
str2="A"
result=$(echo $str1 | grep "${str2}")
if [[ "$result" != "" ]];then
echo "包含"
else
echo "不包含"
fi
2、利用字串運算子
str1="hellow"
str2="low"
if [[ $str1 =~ $str2 ]];then
echo "包含"
else
echo "不包含"
fi
3、利用萬用字元
str1="hellow"
str2 ="low"
if [[ $str1 == *$str2* ]];then
echo "包含"
else
echo "不包含"
fi
相關推薦
字串包含關係判斷
1、利用grep查詢 str1="ABC" str2="A" result=$(echo $str1 | grep "${str2}") if [[ "$result" != "" ]];then echo "包含" else echo "不包含" fi 2、
Shell判斷字串包含關係的方法小結
用Shell指令碼的編寫中,常用到字串包含關係的判斷。 利用grep查詢 strA="long string" strB="string" result=$(echo $strA | grep "${strB}") if [[ "$resu
【轉】Shell判斷字串包含關係的幾種方法
下面是直接copy的內容: (本來是不打算copy的,但是每次用到或看的時候都要跳轉,感覺挺麻煩的。就直接copy了。) 方法一:利用grep查詢 1 strA="long string" 2 strB="string" 3 result=$(echo $
Mysql字串欄位判斷是否包含某個字串的2種方法
原文連結: 方法二: 利用mysql 字串函式 find_in_set(); 複製程式碼程式碼如下: SELECT * FROM users WHERE find_in_set('[email protected]', emails); 這樣
python判斷字串包含中文、數字、英文
1.判斷字串只包含中文:#encoding=utf-8 import sys reload(sys) sys.setdefaultencoding('utf8') def check_contain_chinese(check_str): flag = True
lua判斷字串包含另一個字串
--string.find("元字串","模式字串") 如下: print(string.find("CCBWebView/*/iPhone OS/*/10.3.2/*/4.04/*/750*129
PostgreSQL 判斷字串包含的幾種方法
判斷字串包含的幾種方法: 1. position(substring in string): postgres=# select position('aa' in 'abcd'); position ---------- 0 (1
如何判斷字串包含的是數字
全為整數,而且第一個數字不為0 字串程式設計是LABVIEW的程式設計難點之一,有的時候,用一整天的時間做一個字串處理的VI是常有的事,尤其是對各類專用裝置特殊的通訊協議和禎結構. 從最簡單的無符號10進位制整數談起 1.無符號DEC整數 比
java判斷一個字串包含多少其他字串
public static int getSubCount_2(String str, String key) { int count = 0; int index = 0; while ((index = str
boost::algorithm用法詳解之字串關係判斷
下面先列舉幾個常用的: #define i_end_with boost::iends_with #define i_start_with boost::istarts_with #define i_contain boost::icontains #define i_eq
Mysql字串欄位判斷是否包含某個字串的3種方法
方法一: SELECT * FROM users WHERE emails like "%[email protected]%"; 方法二: 利用mysql 字串函式 find_in_set(); SELECT * FROM users WHERE fi
iOS 判斷字串是否為空字串 && 判斷字串包含那個字元
- (BOOL) isBlankString:(NSString *)string { if (string == nil || string == NULL) { return YES; } if ([string isKindOf
面試題:一個字串包含英文和特殊字元,特殊字元不變,英文順序反過來,比如string str="[email
public class Reverse { public static void main(String[] args) { String str = "[email protected]!tk"; char[] chars = str.toCh
python 從鍵盤輸入一個字串,將小寫字母全部轉換成大寫字母,將字串以列表的形式輸出(如果字串包含整數取整型)?
str1 = input("請輸入任意字串: ") list1= [] #儲存字串 list2= [] #儲存數字 for i in str1: if i.isdigit() == True: #判斷當前字元是否為字元 list2.append(int(i)) else:
字串包含
題目描述 給定兩個分別由字母組成的字串A和字串B,字串B的長度比字串A短。請問,如何最快地判斷字串B中所有字母是否都在字串A裡? 為了簡單起見,我們規定輸入的字串只包含大寫英文字母,請實現函式bool StringContains(string &A, string &B
微信小程式-多層餅圖/包含關係餅圖/自定義餅圖關係模式
效果圖如下 WXML <view class='chart_wrapper'> <view class='chart_wrapper'> <view class='chart_mark'> <view class
死磕演算法·字串問題】判斷A中是否存在一棵子樹與B樹的拓撲結構完全相同·kmp演算法應用
題目大意: 對於兩棵彼此獨立的二叉樹A和B,請編寫一個高效演算法,檢查A中是否存在一棵子樹與B樹的拓撲結構完全相同。給定兩棵二叉樹的頭結點A和B,請返回一個bool值,代表A中是否存在一棵同構於B的子樹。 許多題目可以轉化為字串型別題目進行求解。此題判斷A中是否有一棵拓撲結構和B相同
hdu 5961 傳遞(傳遞關係判斷)
傳遞關係 存在a->b b->c則定存在a->c #include<bits/stdc++.h> using namespace std; vector<
利用Turf.js實現點線面幾何體的拓撲關係判斷
第一步:先引用js檔案 <script src='https://npmcdn.com/@turf/turf/turf.min.js'></script> 第二步:呼叫函式,判斷關係 booleanClockwise(line) /
自己動手編寫IPv4地址包含關係測試的小指令碼
工作中需要對地址包含關係進行測試,現有ipaddress標準庫和IPy無法滿足,於是自己動手編寫小指令碼,主要實現== , in, <等專用功能,其他功能可以後續用到再補充,例如迭代列印網段內所有地址,輸出字首長度等等。 一,含有的類:Host類:主機地址,eg, Host('192.168.1.1'