处理字符串变量的问题。
1. 如何把字符串变量中的字母一个一个读出来?如'asdf'读出为: 'a','s'...
2. 把字符转换为ASCII码,及把ASCII码转为字符
注意是字符串变量不是数组。
问题点数:20、回复次数:4Top
1 楼netken(小肯)回复于 2001-08-19 11:12:01 得分 10
substr($string,$position,1);
然后每次 $position++;
i.e.
$position=0;
print $a."\n" while($a=substr($string,$position,1));
或者用 reg exp 来分割
i.e.
print $1."\n" while ($string =~ s/(.)// );
或者用 split 来分割成一个 array
i.e.
@a = split('',@string);
关于ascii转换,前面有类似的帖子可以查询
用 ord,chr 函数
i.e.
ord "a";
chr 97;Top
2 楼iamxxg(bigfoot)回复于 2001-08-19 21:53:25 得分 10
补充:
for($n=0;$n<length($string);$n++) {
$char=substr($string,$n,1);
}Top
3 楼netken(小肯)回复于 2001-08-20 04:50:54 得分 0
修改:while那个应该是
$position=0;
print $a."\n" while($a=substr($string,$position++,1));
Top
4 楼bluely()回复于 2001-08-20 18:47:25 得分 0
我去试试,谢谢,分数先瓜分了吧。!!Top





