check if string contain substring

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ivan Demkovitch

    #1

    check if string contain substring

    Hi!

    I would like to check if string contain specific substring.

    How to do it?

    P.S. I've done something stupid like

    String.Replace

    If str1<>str2....



  • Mark

    #2
    Re: check if string contain substring

    Ivan,

    In the .net help index, lookup the string class, and then look at all the
    methods available. For instance, the IndexOf method might do the trick.

    String strMyString = "Neat";
    Int32 iLocation = strMyString.Ind exOf("a");

    if ( iLocation >= 0 )
    {
    //Do something
    }

    Mark

    "Ivan Demkovitch" <i@a.b> wrote in message
    news:%23nkd6ILm DHA.2512@TK2MSF TNGP09.phx.gbl. ..[color=blue]
    > Hi!
    >
    > I would like to check if string contain specific substring.
    >
    > How to do it?
    >
    > P.S. I've done something stupid like
    >
    > String.Replace
    >
    > If str1<>str2....
    >
    >
    >[/color]


    Comment

    • Dave Jefferson

      #3
      Re: check if string contain substring

      I would do something like this:

      if (str.IndexOf(st r2) == -1) ...

      IndexOf returns -1 it cannot find str2 in str1

      Dave
      [color=blue]
      > Hi!
      >
      > I would like to check if string contain specific substring.
      >
      > How to do it?
      >
      > P.S. I've done something stupid like
      >
      > String.Replace
      >
      > If str1<>str2....
      >
      >
      >[/color]



      --
      Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/

      Comment

      • Ivan Demkovitch

        #4
        Re: check if string contain substring

        Thank you guys!

        Thats indeed nicer way of doing it.

        I looked thru sring class like 5 times and didn't stop on IndexOf() :-)



        "Ivan Demkovitch" <i@a.b> wrote in message
        news:%23nkd6ILm DHA.2512@TK2MSF TNGP09.phx.gbl. ..[color=blue]
        > Hi!
        >
        > I would like to check if string contain specific substring.
        >
        > How to do it?
        >
        > P.S. I've done something stupid like
        >
        > String.Replace
        >
        > If str1<>str2....
        >
        >
        >[/color]


        Comment

        Working...