Hi to all,
I'm working on an AIR application using Flex Builder 3 with Flex SDK 4.0 installed. The main idea of the application is to read an external text file (*.txt) into a TextArea and after clicking a button I want some text range (e.g. from line 100-200) to be copied into another TextArea.
I've made almost everything, but I don't know how to extract a specific range of text between certain text lines.
I alredy made a code to get the exact number of lines of the whole input text file:
PHP Code:
//get number of lines
function getNumLines(event:MouseEvent):void{
saveButton.enabled = true;
var nLines:uint = inputField.mx_internal::getTextField().numLines;
for (var i:Number = 0;i<nLines;i++){
var Line1:String = inputField.mx_internal::getTextField().getLineText(i);
var str:String = (1+i) + " " + Line1;
outputField.text += str;
}
}
extractButton.addEventListener(MouseEvent.CLICK,getNumLines);
I've searched over the net about this problem and I've found
getText() method which could be possible solution to fix this problem, but I really don't know how to implement it in my case.
If someone have an idea or solution, will be of great help!
Thanks in advance,
Nikola
function getLines( textField:TextField, start:int, count:int ):String { var a:Array = []; var i:int = start; var n:int = start + count; while( i < n ) { a.push( textField.getLineText( i ) ); i ++; } var s:String = a.join( "" ); if( s.substr( -1 ) == "\r" ) { s = s.substr( 0, -1 ); } return s; }