a String "contains" method

Hello,

I am new to J#, migrating from Sun's java. I want to do something simular to this in J#:

String dayList [] = {"good day", "bad day"};
for (int a=0; a<2; a++) //iterate through the 2 Strings
if (dayList[ a ].contains( "good" )) //if the String contains "good"
System.out.println(dayList[ a ]);

I do not see a method "contains( String s )" in the J# String class in the msdn documentation. I am wondering how best to go about this in J#.

Thank you,

Eric



Answer this question

a String "contains" method

  • barvan

    Same method exists in the VJ#2.0 also but it stats with "C" (Uppercase)

    String dayList[] = { "good day", "bad day" };

    for (int a = 0; a < 2; a++) //iterate through the 2 Strings

    if (dayListAngel.Contains("good")) //if the String contains "good"

    System.out.println(dayListAngel);

    Thanks



  • Karun123

    Thanks a lot, that's just what I need.

    I was thinking I'd have to cycle through all the characters of the array, comparing for the search key. Fortunately your solution's much faster and simpler.

    Thanks again,

    Eric


  • Slag

    You can use IndexOf and check if this doesn't return -1.


  • TheChemist

    You are welcome!


  • a String "contains" method