フレックス3.行ごとにテキストを分割する方法
私はTextAreaオブジェクトを作成しました。それから、テキストを入力しました。それから、TextArea.textプロパティを使ってこのテキストを取得しました。
私は行で得たテキストを分割して文字列の配列に変換できますか?
フレックス3.行ごとにテキストを分割する方法
私はTextAreaオブジェクトを作成しました。それから、テキストを入力しました。それから、TextArea.textプロパティを使ってこのテキストを取得しました。
私は行で得たテキストを分割して文字列の配列に変換できますか?
「\ n」が機能しない場合は、「\ r」(キャリッジリターン)を試してください。どのように動作するかを示すコードがあります。ボックスに入力すると、配列の内容が変わるのがわかります:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="onCreationComplete(event)">
<mx:Script>
<![CDATA[
import mx.events.CollectionEvent;
import mx.collections.ArrayCollection;
import mx.events.FlexEvent;
[Bindable]
private var ac:ArrayCollection;
protected function onCreationComplete(event:FlexEvent):void
{
ac = new ArrayCollection();
ac.addEventListener(CollectionEvent.COLLECTION_CHANGE, onCollectionChange);
}
protected function onKeyUp(event:KeyboardEvent):void
{
ac.source = event.target.text.split("\r");
}
protected function onCollectionChange(event:CollectionEvent):void
{
contents.text = ac.source.join("\r");
}
]]>
</mx:Script>
<mx:TextArea id="input" x="19" y="22" width="273" height="175" keyUp="onKeyUp(event)" />
<mx:TextArea id="contents" x="112" y="249" width="180" height="175" editable="false" />
<mx:Label x="19" y="222" text="Array Length:" fontWeight="bold" />
<mx:Label x="37" y="250" text="Contents:" fontWeight="bold" />
<mx:Label x="111" y="222" text="{ac.length}" />
</mx:Application>
希望します!
「分割された」とはどういう意味ですか?通常は、textwidthの前の最後の空白のテキストをスキャンし、その行を呼び出します。
私は複数のテキストを文字列の配列に変換する必要があります。各要素は別々の行です(文字列ですか?) – simplemagik
this siteによれば、改行フィードの文字は "\ n"です。 "\ n"でSplit()関数を使うと、文字列を改行で区切られた文字列に分割することができます。
この方法でこの問題を解決するのは私の最初の考えでした。しかし、それは動作しません! – simplemagik
ありがとう!それは私が必要なものです! – simplemagik