سؤال

  var sample:String = filterBox.text; 

Based on the String I get from TextInput, a Button has to be disabled if the String has only white spaces and enabled only otherwise.

I want to check if the String has only white spaces.

Is/Are there any inbuilt methods in flex for this? I saw some answers for Java to use trim method. But its not available in Flex. Please help me out.

هل كانت مفيدة؟

المحلول

You can do the following

StringUtil.trim(string);

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/utils/StringUtil.html

String has a lot of methods which match for patterns you can find it here. http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/String.html

نصائح أخرى

Using

private const r:RegExp = /\S/;

private function isEmpty(str:String):Boolean {
    return = !r.test(str);
}

then

trace(isEmpty("hello world")); //false
trace(isEmpty("  ")); //true
trace(isEmpty(" ")); //true
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top