SgDotNet
Singapore Professional .NET User Group -For Cool Developers

how to find instring in C# given string?

rated by 0 users
This post has 3 Replies | 1 Follower

Top 500 Contributor
Posts 41
Radhiga Posted: 06-28-2005 11:07 PM

Hello Friends,

                        I need a clarification to find the instring in C#. Generally we can use indexof to find if the given string/character  is present. But if i use any special characters in that matching string, it doesnt match it..

For example,

          i want to find out "obj_name" in the "objectname,obj_name" string.

if i use string.indexof("obj_name") >0 , it doesnt validated this bcoz of the "_" character. so how can i solve this..

for timebeing i have used RegEx to slove this..

but suggestion pls

Top 50 Contributor
Posts 154

first i think you mean sub-string rather than 'instring'. what is an instring anyway?

second, i tested your sample code snippet and it worked fine, returning True. So apparently there is no problem.

also, personally I find regex is a very powerful solution and you shouldn't think of it as a kludge.

http://feelite.com/blog
Top 25 Contributor
Posts 1,221

Using RegEx is the *politically correct* way of doing things. But IMO, if you can do something that's alot simplier and understandable, do it.

I haven't tried whether indexof is valid with "_" character, but I guess felite has already checked it out.

Regards, triplez ------------------------------ http://triplez.mine.nu/blogs
Top 50 Contributor
Posts 154
you should give more information as clearly the sample code runs fine on other machines. for example, are you doing some non-unicode encoding stuff?
http://feelite.com/blog
Page 1 of 1 (4 items) | RSS
Copyright SgDotNet 2004-2009
Powered by Community Server (Commercial Edition), by Telligent Systems