python的类里面可以定义__str__()函数。如果定义了这个函数,当str()这个类的对像的时候就是调用的类的__str__()函数。__str__()函数必须要返回一个字符串。 同样的__unicode__也是这个道理。此外还有很多其他的函数也是这样。但不是所有的函数都可以,例如要是自定一个__Atest__()就不行。代码如下: #coding:utf-8 class AA(): def __Atest__(self): print "hello" def __unicode__(self): ...
by pgt112you - Python文档中心 - 2009-10-11 20:36:36 阅读(2013) 回复(0)
printf("%s", str) vs. printf(str) Created: Fang lungang 03-08-2007Modified: Fang lungang 03-08-2007 21:35> 从 The C Programming Language 2nd 看到的 printf 一个需要注意的细节:即使被打印的本身就只有一个字符串,最好也别直接打印,而要用格式符 %s。其它格式输出的函数应该也类似。 #include int main() { char* str= "a string with % may not workn"; printf ("%s", str); printf (str);...
小弟c语言不精,基础不好 感问char *str跟 char str[]的区别 [code] int main() { char *str="hello"; char str2[6]="hello"; *str="other"; str2[6]="other"; if(!strcmp(str,"hello"))printf("\n*str"); if(!strcmp(str2,"hello"))printf("\nstr[]"); return 0; } [/code] 上面的两种情况会有不同的结果 [ 本帖最后由 ydlhero 于 2006-8-10 16:37 编辑 ]
今有类似字符串如下: string =
string = 'abc'>xxxxx
str函数里有没有某个函数或者某些函数凑合起来,然后把<>和它里面的内容去掉,之保留xxxxx内容。? 查了半天,没个头绪。
[color="#0000bb"] 字符串取代。 [color="#ff8000"]语法: string str_replace(string needle, string str, string haystack); [color="#ff8000"]返回值: 字符串 [color="#ff8000"]函数种类: 资料处理 [color="#ff8000"]内容说明 本函数将字符串 str 代入 haystack 字符串中,将所有的 needle 置换成 str。mlevine@adtraq.com (11-Apr-1999) 指出在 PHP 3.0.7 版,本函数有些 bug,而...
查资料得 (?=...) 如果前瞻查找断言成功,返回真 但是我还是想不明白 0不也匹配\d的么? 那到底什么情况下断言会查找成功呢? [ 本帖最后由 justlooks 于 2009-2-23 13:14 编辑 ]
function ChkUtil() { //校验是否为空(先删除二边空格再验证) ChkUtil.isNull = function (str) { if (null == str ||""== str.trim()) { return true; } else { return false; } }; } 这个该怎么调用啊? 其中ChkUtil.isNull 和 this.isNull这样写一样吗? JScript code script type="text/javascript"> function ChkUtil() { d="123" //校?是否?空(先?除二?空格再??) ChkUtil.isNull = function (str) { if (null == ...
function ChkUtil() { //校验是否为空(先删除二边空格再验证) ChkUtil.isNull = function (str) { if (null == str ||""== str.trim()) { return true; } else { return false; } }; } 这个该怎么调用啊? 其中ChkUtil.isNull 和 this.isNull这样写一样吗? JScript code script type="text/javascript"> function ChkUtil() { d="123" //校?是否?空(先?除二?空格再??) ChkUtil.isNull = function (str) { if (null == ...
#include
char str[10]; memset(str,0,sizeof(str))和memset(&str,0,sizeof(str))的区别在那里? 请高手指点阿!!! [ 本帖最后由 wangjm213 于 2006-2-28 10:36 编辑 ]