Select a line within a Textarea

Discussions and Tech Support related to the iMacros Firefox Add-on.

Moderator: iMacros Moderators

Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the Google search box (at the top of each forum page) to see if a similar problem or question has already been addressed. This will search the entire contents of the forums as well as the iMacros Wiki.
3. We can respond much faster to your posts if you include the following information:

CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST

Answering your own posts (e.g. attempting to "bump" your topic) drops your topic from the list of unanswered threads, so it may actually receive less views.

Select a line within a Textarea

by Stigi on Tue Oct 06, 2009 11:22 am

Hi Guys,

I realise its easy enough extracting everything within a textarea but is it possible to select only 1 line within it? Like just the 3rd or 4th line?
Stigi
 
Posts: 1
Joined: Tue Oct 06, 2009 11:18 am

Re: Select a line within a Textarea

by ABooth on Tue Oct 06, 2009 1:41 pm

Stigi wrote:Hi Guys,

I realise its easy enough extracting everything within a textarea but is it possible to select only 1 line within it? Like just the 3rd or 4th line?

No, not from iMacros direct. What is a line? It is a string of text with a line terminator such as CarriageReturn/LineFeed 0D0A hex.
You would need to extract the full content to your scripting language and extract the line from it.

In JavaScript you could do something like: -
Code: Select all
//Returns the line if it exists, otherwise returns a Null String -> ""
function getLine(inString, lineNumber){
    const lineTerminator = "\r\n"; //Carriage return | Linefeed. Standard DOS/MS Windows line terminator.
   
   var returnValue = "";
   var lines = inString.split(lineTerminator); // Separate the string into an array of lines
   
   //Make sure you're not trying to get line 10 from 3 lines of text, for example
   if (lines.length <= lineNumber && lines.length > 0)
      returnValue = lines[lineNumber -1]; //0 based array means lineNumber 1 is lines[0], lineNumber 2 is lines[1] and so on ...
   
   return returnValue; //Returns either "" or the line (without the line terminator)
}

var theTextAreaContent = iimGetLastExtract(); // Extract the string
var theLineIWant = getLine(theTextAreaContent, 5); // Get line 5 from the extract value
iMacros for Firefox supports JavaScript Macros (Scripting)
JavaScript supports Java via LiveConnect

Therefore: You can write powerful macros with iMacros for Firefox. Have a look at this one

Post feature requests here. Maybe one day, they'll pin it?
ABooth
 
Posts: 223
Joined: Mon Aug 10, 2009 9:25 am


Return to iMacros for Firefox

Who is online

Users browsing this forum: Google [Bot] and 4 guests

Website Monitoring