字符串中的第一个不同字符 [英] first different character in string

查看:81
本文介绍了字符串中的第一个不同字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种快速的方法可以找到第一个字符的索引不同的

两个字符串?


例如,如果我有字符串

" abcdefghijkl"



" abcdefxyz"

我希望返回值为6。


无论是在C#还是C ++中。 (我显然知道如何通过循环遍历字符数组中的

字符来实现它,但我想知道是否有一些

smart-alec内存操作函数, asm甚至是正则表达式我可以使用

来做它。)


谢谢

Is there a quick way to find the index of the first character different in
two strings?

For instance, if I had the strings
"abcdefghijkl"
and
"abcdefxyz"
I would want the return value to be 6.

Either in C# or C++. (I obviously know how to do it by looping through the
characters in the character array, but I was wondering if there was some
smart-alec memory-manipulation function, asm even, or regexes I could use
that would do it.)

Thanks

推荐答案

在32位环境中,最快的方法是找到4字节的

边界,并开始一次读取和比较4个字节。如果发现不匹配

,你会挖掘并在字节/字级别比较它们(取决于是否

你的编码是8位还是16位)


在x86 asm中,你应该使用字符串优化的lodsb,cmpsb说明。


-vJ


" Beeeeeves" < 1234512345789123456789>在消息中写道

news:uy ****************** @ TK2MSFTNGP10.phx.gbl ...
In a 32 bit environment, the fastest approach would be find the 4-byte
boundary and start reading and comparing 4 bytes at a time. When a mismatch
is found, you''ll dig in and compare them at byte/word level (depending on if
your encoding is 8-bit or 16-bit)

In x86 asm, you should use the string optimized lodsb, cmpsb instructions.

-vJ

"Beeeeeves" <1234512345789123456789> wrote in message
news:uy******************@TK2MSFTNGP10.phx.gbl...
是有一个快速的方法来找到两个字符串中第一个字符的索引不同吗?

例如,如果我有字符串
" abcdefghijkl"

" abcdefxyz"
我希望返回值为6.

在C#或C ++中。 (我显然知道如何通过循环遍历字符数组中的
字符来实现它,但我想知道是否有一些
smart-alec内存操作函数,甚至是asm,还是我可以使用的正则表达式
就可以了。)

谢谢
Is there a quick way to find the index of the first character different in
two strings?

For instance, if I had the strings
"abcdefghijkl"
and
"abcdefxyz"
I would want the return value to be 6.

Either in C# or C++. (I obviously know how to do it by looping through the
characters in the character array, but I was wondering if there was some
smart-alec memory-manipulation function, asm even, or regexes I could use
that would do it.)

Thanks





Vijaye Raji <无************* @ hotmail.com>在消息中写道

新闻:O3 ************* @ TK2MSFTNGP10.phx.gbl ...

"Vijaye Raji" <no*************@hotmail.com> wrote in message
news:O3*************@TK2MSFTNGP10.phx.gbl...
在32位环境中,最快的方法是找到4字节的边界,并开始一次读取和比较4个字节。当发现
不匹配时,你会挖掘并在字节/字级别比较它们(如果你的编码是8位或16位,则取决于



这就是我所采用的。

在x86 asm中,你应该使用字符串优化的lodsb,cmpsb指令。


知道任何例子吗?

-vJ

Beeeeeves < 1234512345789123456789>在消息中写道
新闻:uy ****************** @ TK2MSFTNGP10.phx.gbl ...
In a 32 bit environment, the fastest approach would be find the 4-byte
boundary and start reading and comparing 4 bytes at a time. When a mismatch is found, you''ll dig in and compare them at byte/word level (depending on if your encoding is 8-bit or 16-bit)
That''s what I''ve resorted to.

In x86 asm, you should use the string optimized lodsb, cmpsb instructions.
Know any examples?

-vJ

"Beeeeeves" <1234512345789123456789> wrote in message
news:uy******************@TK2MSFTNGP10.phx.gbl...
有没有快速的方法在两个字符串中找到不同
的第一个字符的索引?

例如,如果我有字符串
" abcdefghijkl"

abcdefxyz
我希望返回值为6.

在C#或C ++中。 (我显然知道如何通过循环
字符数组中的字符来做到这一点,但我想知道是否有一些
smart-alec内存操作函数,asm甚至或正则表达式我可以
使用它会这样做。)

谢谢
Is there a quick way to find the index of the first character different in two strings?

For instance, if I had the strings
"abcdefghijkl"
and
"abcdefxyz"
I would want the return value to be 6.

Either in C# or C++. (I obviously know how to do it by looping through the characters in the character array, but I was wondering if there was some
smart-alec memory-manipulation function, asm even, or regexes I could use that would do it.)

Thanks




来吧,你知道你想要的。我很想在这个程序中得到一些汇编语言

;-)


" Vijaye Raji" <无************* @ hotmail.com>在消息中写道

新闻:O3 ************* @ TK2MSFTNGP10.phx.gbl ...
Come on, you know you want to. I''d love to get a bit of assembly language
into this program ;-)

"Vijaye Raji" <no*************@hotmail.com> wrote in message
news:O3*************@TK2MSFTNGP10.phx.gbl...
在32位环境中,最快的方法是找到4字节的边界,并开始一次读取和比较4个字节。当找到
不匹配时,你会挖掘并在字节/字级别比较它们(如果你的编码是8位或16位,则取决于


>在x86 asm中,你应该使用字符串优化的lodsb,cmpsb指令。

-vJ

" Beeeeeves" < 1234512345789123456789>在消息中写道
新闻:uy ****************** @ TK2MSFTNGP10.phx.gbl ...
In a 32 bit environment, the fastest approach would be find the 4-byte
boundary and start reading and comparing 4 bytes at a time. When a mismatch is found, you''ll dig in and compare them at byte/word level (depending on if your encoding is 8-bit or 16-bit)

In x86 asm, you should use the string optimized lodsb, cmpsb instructions.

-vJ

"Beeeeeves" <1234512345789123456789> wrote in message
news:uy******************@TK2MSFTNGP10.phx.gbl...
有没有快速的方法在两个字符串中找到不同
的第一个字符的索引?

例如,如果我有字符串
" abcdefghijkl"

abcdefxyz
我希望返回值为6.

在C#或C ++中。 (我显然知道如何通过循环
字符数组中的字符来做到这一点,但我想知道是否有一些
smart-alec内存操作函数,asm甚至或正则表达式我可以
用它来做。)

Is there a quick way to find the index of the first character different in two strings?

For instance, if I had the strings
"abcdefghijkl"
and
"abcdefxyz"
I would want the return value to be 6.

Either in C# or C++. (I obviously know how to do it by looping through the characters in the character array, but I was wondering if there was some
smart-alec memory-manipulation function, asm even, or regexes I could use that would do it.)

Thanks




这篇关于字符串中的第一个不同字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆