Questions tagged «string»

字符串是有限的符号序列,通常用于文本,尽管有时用于任意数据。




4
匹配模式或为空字符串的正则表达式
我有以下与电子邮件地址格式匹配的正则表达式: ^[\w\.\-]+@([\w\-]+\.)+[a-zA-Z]+$ 这用于使用JavaScript进行表单验证。但是,这是一个可选字段。因此,如何更改此正则表达式以匹配电子邮件地址格式或空字符串? 根据我对正则表达式的有限了解,我认为\b匹配一个空字符串,并|表示“ Or”,因此我尝试执行以下操作,但此方法无效: ^[\w\.\-]+@([\w\-]+\.)+[a-zA-Z]+$|\b


7
两个熊猫列的字符串串联
我有以下内容DataFrame: from pandas import * df = DataFrame({'foo':['a','b','c'], 'bar':[1, 2, 3]}) 看起来像这样: bar foo 0 1 a 1 2 b 2 3 c 现在我想拥有类似的东西: bar 0 1 is a 1 2 is b 2 3 is c 我该如何实现?我尝试了以下方法: df['foo'] = '%s is %s' % (df['bar'], df['foo']) 但这给我一个错误的结果: >>>print df.ix[0] bar …


3
更新中的T-SQL字符串替换
我需要更新一列的值,并在现有值上进行子字符串替换。 例: 数据包括abc@domain1,pqr@domain2等等。 我需要更新@domain2替换为的值@domain1。
83 string  tsql  replace 



9
从C#中包含&nbsp的字符串中删除HTML标签
如何在C#中使用正则表达式删除所有HTML标记,包括&nbsp。我的弦看起来像 "<div>hello</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div>                                                      </div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div>"
83 c#  html  regex  string 

3
Python中unicode()和encode()函数的用法
我在对路径变量进行编码并将其插入SQLite数据库时遇到问题。我试图用无济于事的encode(“ utf-8”)函数解决此问题。然后,我使用unicode()函数为我提供unicode类型。 print type(path) # <type 'unicode'> path = path.replace("one", "two") # <type 'str'> path = path.encode("utf-8") # <type 'str'> strange path = unicode(path) # <type 'unicode'> 最终我获得了unicode类型,但是当path变量的类型为str时,仍然出现相同的错误 sqlite3.ProgrammingError:除非使用可以解释8位字节串的text_factory(如text_factory = str),否则不得使用8位字节串。强烈建议您改为将应用程序切换为Unicode字符串。 您能帮我解决此错误,并解释encode("utf-8")和unicode()功能的正确用法吗?我经常为此而斗争。 编辑: 此execute()语句引发错误: cur.execute("update docs set path = :fullFilePath where path = :path", locals()) 我忘记更改具有相同问题的fullFilePath变量的编码,但是现在我很困惑。我应该只使用unicode()还是encode(“ utf-8”)还是两者都使用? 我不能用 fullFilePath = …


1
STL字符特征的重点是什么?
我注意到在我的SGI STL参考副本中,有一个有关角色特征的页面,但是我看不到如何使用这些特征?它们是否替换了string.h函数?似乎没有使用它们std::string,例如length()on上的方法std::string未使用Character Traitslength()方法。为什么存在性格特征,并且在实践中曾经使用过它们?

21
查找字符串中第N个出现的字符
我需要创建C#方法来返回字符串中第N个字符的索引的帮助。 例如,'t'字符串中字符的第3次出现"dtststxtu"是5。 (请注意,字符串有4 ts。)
83 c#  string 

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.