支持Unicode的字符串(1)程序

Eva*_*van 8 string unicode

有没有人有一个代码示例用于unicode感知字符串程序?编程语言并不重要.我想要一些与unix命令"strings"基本相同的东西,但它也可以在unicode文本(UTF-16或UTF-8)上运行,拉动英语字符和标点符号的运行.(我只关心英文字符,而不是任何其他字母).

谢谢!

jpa*_*cek 8

你只是想使用它,还是因某些原因坚持使用代码?

在我的Debian系统上,似乎strings命令可以开箱即用.请参阅联机帮助页中的exercept:

  --encoding=encoding
       Select the character encoding of the strings that are to be found.  Possible values for encoding are: s = single-7-bit-byte characters (ASCII, ISO  8859,
       etc.,  default),  S  = single-8-bit-byte characters, b = 16-bit bigendian, l = 16-bit littleendian, B = 32-bit bigendian, L = 32-bit littleendian. Useful
       for finding wide character strings.
Run Code Online (Sandbox Code Playgroud)

编辑:好的.我不知道C#所以这可能有点毛茸茸,但基本上,你需要搜索交替的零和英文字符的序列.

byte b;
int i=0;
while(!endOfInput()) {
  b=getNextByte();
LoopBegin:
  if(!isEnglish(b)) {
    if(i>0) // report successful match of length i
    i=0;
    continue;
  }
  if(endOfInput()) break;
  if((b=getNextByte())!=0)
    goto LoopBegin;
  i++; // found another character
}
Run Code Online (Sandbox Code Playgroud)

这应该适用于小端.