s*****w 发帖数: 1527 | 1 i have the following code
$forthChar = substr($tmpLine, 3, 1);
print "--".$forthChar."--\n";
if ($forthChar == " ") {
} else {
print "not same\n";
}
this is what i get |
p**i 发帖数: 688 | 2
$forthChar eq " " , == is for numeric equality
【在 s*****w 的大作中提到】 : i have the following code : $forthChar = substr($tmpLine, 3, 1); : print "--".$forthChar."--\n"; : if ($forthChar == " ") { : } else { : print "not same\n"; : } : this is what i get
|
m*********g 发帖数: 273 | 3 right
use eq please
【在 p**i 的大作中提到】 : : $forthChar eq " " , == is for numeric equality
|
t*****g 发帖数: 1275 | 4 use eq instead of == for string comparison.
Why don't you use regex
$tmpLine =~ /^.{3} /
【在 s*****w 的大作中提到】 : i have the following code : $forthChar = substr($tmpLine, 3, 1); : print "--".$forthChar."--\n"; : if ($forthChar == " ") { : } else { : print "not same\n"; : } : this is what i get
|
L*1 发帖数: 11537 | 5 十多年前也犯过用“==”的错误,弄了一天才明白要用“eq”。
【在 s*****w 的大作中提到】 : i have the following code : $forthChar = substr($tmpLine, 3, 1); : print "--".$forthChar."--\n"; : if ($forthChar == " ") { : } else { : print "not same\n"; : } : this is what i get
|