是否有內置函數用於確定字符是否存在於字符串中。你怎麼能確定一個值是一個字符串還是一個數字。在帶有圖案的字符串中搜索Perl字符
0
A
回答
0
有一個內置的功能在Perl稱爲索引功能也使用模式匹配像
使用指數:指數($ stringvariable,「字符搜索」); 以確定某個數字是否使用代碼m/\ d/ 如果您想確定某個值是否爲字符串使用m/\ D/ 使用模式匹配技術。
0
Perl的標量是一個字符串,並在同一時間。爲了測試標量是否可被用作一個數沒有任何警告:
use Scalar::Util qw/looks_like_number/;
my $variable = ...;
if (not defined $variable) {
# it is not usable as either a number or a string, as it is "undef"
}
elsif (looks_like_number $variable) {
# it is a number, but can also be used as a string
}
else {
# you can use it as a string
}
實際上,故事是更復雜的處理對象位其可以是或可以不是可作爲數字或字符串。此外,looks_like_number
可以返回Infinity
和NaN
(不是數字)的真實值,這可能不是您認爲是數字的值。
要測試一個字符串是否包含一些子,你可以使用正則表達式或index
功能:
my $haystack = "foo";
my $needle = "o";
if (0 <= index $haystack, $needle) {
# the $haystack contains the $needle
}
有些人喜歡等效試驗-1 != index ...
代替。
相關問題
- 1. 搜索圖案在字符串
- 2. 字符串圖案在多維字符串數組搜索[,]
- 3. 搜索字符圖案
- 4. URL搜索帶有file_get_contents的字符串
- 5. 搜索字符串中的字符串
- 6. 在perl中搜索帶有特定字符的單詞
- 7. PHP搜索字符串(帶通配符)
- 8. 模式的Perl搜索字符串:*@enron.com
- 9. 搜索字符串中的字符串,使其在原有的字符串
- 10. 在字符串中搜索字符串的所有實例
- 11. 搜索字符串中的字符
- 12. 字符串中的字符搜索
- 13. 搜索字符串中的字符集
- 14. 搜索字符串值中的字符
- 15. 在字符串中搜索'$'
- 16. 搜索字符串內的字符串
- 17. 插入標籤到搜索字符串/字符串案例
- 18. perl在我的字符串中搜索數字
- 19. 搜索子字符串並在Perl中存儲字符串的另一部分
- 20. 帶字符串的二叉搜索樹
- 21. 在MongoDB文檔中搜索帶有特殊字符的字符串
- 22. 在帶有NSScanner的if語句中搜索字符串?
- 23. 在cscope中如何搜索帶有句點的字符串?
- 24. 如何在django中搜索帶有url模式的字符串?
- 25. 搜索字符串
- 26. 字符串搜索
- 27. 搜索字符串
- 28. 搜索字符串
- 29. 搜索字符串
- 30. 搜索字符串
http://perldoc.perl.org/functions/index.html –