2012-11-06 30 views
0

我有一个flex中的文本框,我试图分割用户输入的金额。代码是这样的:柔性拆分字符串的点不起作用

var splitAmount:Array = toAmountLocal.split("\\."); 

试图用点不同的选择,但没有什么工作,每次都返回其作为splitAmount.length仅1()。

+1

岂不是'toAmountLocal.split(“\”)' – anubhava

+0

尝试,但没有工作 – Nirmal

+0

你在textbox..this输入的内容量可能是有关输入本身 – Anirudha

回答

1

如果您使用字符串作为split方法的参数,则不必转义任何内容;只是做:

toAmountLocal.split("."); 

不过,如果你想使用正则表达式作为参数,那么你将有只有一个反斜杠逃脱点,像这样:

toAmountLocal.split(/\./); 
0

下面的代码可以帮助你:我已经添加了评论,你在逻辑中缺少什么。

<?xml version="1.0" encoding="utf-8"?> 
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
       xmlns:s="library://ns.adobe.com/flex/spark" 
       xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" 
       creationComplete="init()"> 

    <fx:Script> 
     <![CDATA[ 
      import mx.controls.Alert; 

      [Bindable] 
      private var toAmountLocal:String = "123.45.6.78"; 

      private function onClickHandler():void 
      { 
       //if user is entering value your local variable should be updated. 
       toAmountLocal = inputID.text; 
       var splitAmount:Array = toAmountLocal.split('.'); 
       Alert.show(splitAmount.length.toString()) 
      } 
     ]]> 
    </fx:Script> 

    <fx:Declarations> 
     <!-- Place non-visual elements (e.g., services, value objects) here --> 
    </fx:Declarations> 

    <s:layout> 
     <s:VerticalLayout/> 
    </s:layout> 

    <s:TextInput id="inputID" text="{toAmountLocal}"/> 
    <s:Button label="Split" click="onClickHandler()"/> 

</s:Application>