Questions tagged «string»

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

3
Python TypeError:格式字符串的参数不足
这是输出。我相信这些是utf-8字符串...其中一些可以是NoneType,但是在类似这样的字符串之前会立即失败... instr = "'%s', '%s', '%d', '%s', '%s', '%s', '%s'" % softname, procversion, int(percent), exe, description, company, procurl TypeError:格式字符串的参数不足 虽然是7比7?

15
python中的n克,四克,五克,六克?
我正在寻找一种将文本拆分为n-gram的方法。通常我会做类似的事情: import nltk from nltk import bigrams string = "I really like python, it's pretty awesome." string_bigrams = bigrams(string) print string_bigrams 我知道nltk仅提供二元组和三元组,但是有没有办法将我的文本分为四克,五克甚至一百克? 谢谢!
137 python  string  nltk  n-gram 

13
我可以“乘以”一个字符串(在C#中)吗?
假设我有一个字符串,例如 string snip = "</li></ul>"; 我想基本上将它多次写入,具体取决于某个整数值。 string snip = "</li></ul>"; int multiplier = 2; // TODO: magic code to do this // snip * multiplier = "</li></ul></li></ul>"; 编辑:我知道我可以很容易地编写自己的函数来实现这一点,我只是想知道是否有一些我不知道的奇怪的字符串运算符


13
突出显示PHP中两个字符串之间的区别
突出显示PHP中两个字符串之间的区别的最简单方法是什么? 我正在考虑“堆栈溢出”编辑历史记录页面的内容,其中新文本为绿色,已删除文本为红色。如果有任何预写的函数或类可用,那将是理想的。
136 php  string  diff  word-diff 


4
重用String.format中的参数?
String hello = "Hello"; String.format("%s %s %s %s %s %s", hello, hello, hello, hello, hello, hello); hello hello hello hello hello hello hello变量是否需要在对format方法的调用中重复多次,还是有一个速记版本可以让您一次指定要应用于所有%s标记的参数?

10
BestPractice-将字符串的第一个字符转换为小写
我想要一种将字符串的第一个字符转换为小写的方法。 我的方法: 1。 public static string ReplaceFirstCharacterToLowerVariant(string name) { return String.Format("{0}{1}", name.First().ToString().ToLowerInvariant(), name.Substring(1)); } 2。 public static IEnumerable<char> FirstLetterToLowerCase(string value) { var firstChar = (byte)value.First(); return string.Format("{0}{1}", (char)(firstChar + 32), value.Substring(1)); } 你会怎么做?
136 c#  .net  string 


10
根据字符串长度修剪字符串
如果长度超过10个字符,我想修剪字符串。 假设字符串长度为12(String s="abcdafghijkl"),则新的修剪后的字符串将包含"abcdefgh.."。 我该如何实现?
136 java  string 



8
如何在Ruby中对字符串进行URL编码
我如何URI::encode像这样的字符串: \x12\x34\x56\x78\x9a\xbc\xde\xf1\x23\x45\x67\x89\xab\xcd\xef\x12\x34\x56\x78\x9a 以如下格式获取它: %124Vx%9A%BC%DE%F1%23Eg%89%AB%CD%EF%124Vx%9A 根据RFC 1738? 这是我尝试过的: irb(main):123:0> URI::encode "\x12\x34\x56\x78\x9a\xbc\xde\xf1\x23\x45\x67\x89\xab\xcd\xef\x12\x34\x56\x78\x9a" ArgumentError: invalid byte sequence in UTF-8 from /usr/local/lib/ruby/1.9.1/uri/common.rb:219:in `gsub' from /usr/local/lib/ruby/1.9.1/uri/common.rb:219:in `escape' from /usr/local/lib/ruby/1.9.1/uri/common.rb:505:in `escape' from (irb):123 from /usr/local/bin/irb:12:in `<main>' 也: irb(main):126:0> CGI::escape "\x12\x34\x56\x78\x9a\xbc\xde\xf1\x23\x45\x67\x89\xab\xcd\xef\x12\x34\x56\x78\x9a" ArgumentError: invalid byte sequence in UTF-8 from /usr/local/lib/ruby/1.9.1/cgi/util.rb:7:in `gsub' from /usr/local/lib/ruby/1.9.1/cgi/util.rb:7:in `escape' from (irb):126 from /usr/local/bin/irb:12:in …


11
从NSString删除所有空格
我一直在尝试摆脱中的空白NSString,但是我尝试过的任何方法都没有用。 我有"this is a test",我想得到"thisisatest"。 我使用过whitespaceCharacterSet,它应该消除空白。 NSString *search = [searchbar.text stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceCharacterSet]]; 但我一直用空格得到相同的字符串。有任何想法吗?

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.