开发者

advanced string management and completion C#

开发者 https://www.devze.com 2022-12-12 04:10 出处:网络
Alright, so I\'m going to jump in with my situation: So I have string[] MyStringArray with \"hello\", \"goodbye\", \"morning\" in it,

Alright, so I'm going to jump in with my situation:

So I have string[] MyStringArray with "hello", "goodbye", "morning" in it,

And now I have a normal string MatchString = "hel",

Now, on a specific trigger, I'd like to be able to loop through the strings in MyStringArray, and find the most开发者_开发百科 likely match, and replace.

So for instance, say I had the string "Hello, and good mor" and then I trigger the event, I'd want the resulting string to be "Hello, and good morning".

Same would be true for "I have got to go, go" -> "I have got to go, goodbye"

EDIT: I want on the trigger to only take the last word, separated by a space.


errrr....

why doesn't "i have got to go, go" turn into "i have got to goodbye, gooodbye"?

and..

"Hello, and good mor" isn't "Hello, and goodbye morning"


You can use the .StartsWith() method, i.e.

foreach (var str in MatchArray)
{
    if (str.StartsWith(MatchString))
    {
        //it's a possible match
    }
}

But you have to deal with multiple matches seperately


Intellisense: Home-Made - Based on Visual Studio By James Gupta

0

精彩评论

暂无评论...
验证码 换一张
取 消