Method to count number of characters in a string?

hi.

i'm trying to write some script that will count the number of characters in a string passed into a constructor and then compare it against another value to check whether the string passed in is valid.

something like this

public class Stringcheck

{

public static int maxStringLength;

public static double minSize;

public static boolean testStringLength(String x)

// Insert method for counting number of chars in String x and name as 'intnumberOfChars

if(number of Chars <= maxStringLength )

{

return true;

}

else

{

return false;

}

}

can someone help me with writing this script.

Thanks

Richard.

[736 byte] By [Richard_Stana] at [2007-10-3 2:40:09]
# 1
ummm, you dont need anything fancy. try:String test = "this is the test string";int length = test.length();
TimSparqa at 2007-7-14 19:38:27 > top of Java-index,Java Essentials,New To Java...
# 2
You can also make your return statement a lot simpler.return x.length() <= maxStringLength;
floundera at 2007-7-14 19:38:27 > top of Java-index,Java Essentials,New To Java...