简体   繁体   中英

Comma separated String looping and checking

I am not sure what is the best way to achieve the same. I have comma separated string like

"sdf,sd,gth,ht,hjh,fds,nhgs"

I have to iterate through the whole string and match it with a value. If the value does not matches then truncate the last part of the string after comma and check for the rest whole string.

For example if the value does not matches with

"sdf,sd,gth,ht,hjh,fds,nhgs"

then truncate the last value after comma and compare the value with

"sdf,sd,gth,ht,hjh,fds"

this time.

Keep iterating through the whole string till it does not matches the value.

Any help in this regard at the earliest is much appreciated.

        var stringToMatch = "abc,def";
        var testString = "abc,def,ghi,jkl";

        bool matches = testString.StartsWith( stringToMatch );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM