什麼是strlen()
的Perl等效物?如何在Perl中獲取字符串的長度?
46
A
回答
70
perldoc -f length length EXPR length Returns the length in characters of the value of EXPR. If EXPR is omitted, returns length of $_. Note that this cannot be used on an entire array or hash to find out how many elements these have. For that, use "scalar @array" and "scalar keys %hash" respectively. Note the characters: if the EXPR is in Unicode, you will get the num- ber of characters, not the number of bytes. To get the length in bytes, use "do { use bytes; length(EXPR) }", see bytes.
28
length($string)
41
雖然「長度()」是應該在任何理智的代碼中使用的正確答案,Abigail's length horror應當提到,如果只爲Perl知識的緣故。
基本上,訣竅在於使用包羅萬象的轉換操作符的返回值:
print "foo" =~ y===c; # prints 3
Ÿ/// C替換所有字符本身(感謝補充選項「C」),並返回被替換的字符數(有效的是字符串長度)。
-2
的length()
功能:
$string ='String Name';
$size=length($string);
相關問題
- 1. 如何獲取字符串長度
- 2. 在JS中獲取字符串長度
- 3. 在StringWriter中獲取字符串長度?
- 4. 如何獲取字符串數組的字符串長度?
- 5. 獲取UTF8中字符串的長度
- 6. 獲取C++中字符串的長度
- 7. 獲取字符串的字節長度
- 8. 如何在PostgreSQL中獲取輸入字符串的長度
- 9. 如何在PHP中獲取字符串的像素長度?
- 10. 如何在PHP中獲取字符串的確切長度?
- 11. C#:如何獲得字符串中的字符串的長度[]
- 12. 如何獲取nodejs中字節的字符串長度?
- 13. 如何在Perl中查找Unicode字符串的長度?
- 14. 如何獲得字符串的長度[] []
- 15. PowerShell 2.0獲取字符串的長度
- 16. 如何在perl中將字符串截斷爲特定長度?
- 17. 如何從數組中分配字符串以獲取字符串的長度?
- 18. 如何獲取TCPDF中字符串的長度?
- 19. 如何從網頁中獲取未知長度的字符串
- 20. 如何獲取Octave中字符串的長度?
- 21. ArrayList:獲取最長字符串的長度,獲取字符串的平均長度
- 22. 獲取奇數長度字符串中的中間字符
- 23. Vb.net獲取子字符串長度
- 24. 獲取奇數長度字符串的中間三個字符
- 25. 獨立於字符編碼的Perl中字符串的長度
- 26. 如何從長字符串中獲取字符串?
- 27. 如何獲得列(Excel)中最長字符串的長度?
- 28. 獲取數組中最長字符串的長度
- 29. 如何獲取Xamarin.Forms的PCL字符串的長度?
- 30. 如何獲取NSTextField的stringValue的字符串長度?
謝謝!輕鬆代表你! :) – Kip 2008-10-21 20:43:12
只是叫我「快速繪製」。 – 2008-10-21 20:43:50