Find Line Number in Text Member

I would like to drop in a line of text after a specific phrase in a text member. To find the right place to drop the text, I must first determine the line number the specific phrase text is located. Now, I can use a REPEAT to walk through each line until it is found, but there must be a more elegant way. The code "Offset" is great for finding the first character number of the specific phrase, but I don't know how to glean the line number from that.
Currently this is how I do it...
repeat with xLineCount = 1 to 100
    if textDoc.line[xLineCount] contains "<specific text phrase>" then
      put RETURN & RETURN & "<new text pasted>" after textDoc.line[xLineCount]
      exit repeat
    end if
  end repeat
Can anyone give me a more elegant approach this?

A more elegant approach might be to use a regular expression, but I'm not sure I understand your requirements well enough to make a sensible recommendation.
You could try the following JavaScript handler and invoke it like:
tMember.text = jsReplace(tMember.text, "<specific text phrase>", "<specific text phrase>" & RETURN & RETURN & "<new text pasted>")
function jsReplace(inStr, strFind, strReplace){
  // error check input
  if(typeof(inStr)      != "string") { return inStr; }
  if(typeof(strFind)    != "string") { return inStr; }
  if(typeof(strReplace) != "string") { return inStr; }
  // search-and-replace
  re = new RegExp(strFind, "g");
  return inStr.replace(re, strReplace);
However, this will place the pasted text immediately after the search phrase and not at the end of the line. It is possible to do this with a regular expression, but I'd have to dust off my copy of Friedl's "Mastering Regular Expressions" to craft it for you and I don't have either the time or inclination at present.

Similar Messages

  • Find line number in text file

    Hi all,
    I need to find the line numbers on a file where a particular string matches.
    for example:
    A lazy cat
    A strong cat and it is black
    Black is not good
    So I will match for the word black and it will give the numbers say line 2 and 3 it found the match.
    I am using the code:
    try{
        // Open the file that is the first
        // command line parameter
          FileInputStream fstream = new FileInputStream("c:\\test.log");
        // Get the object of DataInputStream
          DataInputStream in = new DataInputStream(fstream);
          BufferedReader br = new BufferedReader(new InputStreamReader(in));
          String strLine;
         String[] arr= null;
        //Read File Line By Line
       String regex = "black";
       while ((strLine = br.readLine()) != null)   {
        // Split the sentence into strings based on space
           arr = strLine.split("\\s");
       if (arr[0].equalsIgnoreCase("black"))
          System.out.print("match found");
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(strLine);Thanks in advance.

    camellia wrote:
    I need to find the line numbers on a file where a particular string matches. Then declare a variable for line count. Find where you read in a line. Finally increment this variable each time a line is read.
    It isn't rocket science.
    Mel

  • How to find largest number from text file

    I am using the "Read from text file" block to read the data from my .txt file into labview.  It is now in string format.  I have many numbers in the file.  
    For example:
    0.45
    0.35
    0.12
    1.354
    1.56
    2.89
    5.89
    0.56
    That is what a text file might look like.  I want to find which of these numbers is largest, and do calculations with that number.  I am having trouble with strings/number formats/arrays, etc.  Thanks
    Solved!
    Go to Solution.

    The spreadsheet functions and VIs typically work on strings representing numbers separated by delimiters.  This is a typical way to save a "spreadsheet" (of numbers) to a text file, for example .csv files.  These are quite versatile and powerful functions.  Spend a bit of time becoming familiar with them because you may find yourself using them a lot.
    Lynn

  • Finding Line Number of Warehouses in OITW

    Hi Experts,
    I need to use DTW to update minimum and maximum stock amounts for a Warehouse in my Items, Stock tab.  I figure this is the quickest way to update over 2000 items in B1.
    Trouble is that although I have this warehouse in every item it is not always at the same row number so I thought I would be able to firstly export the row number from each of the items I need to import.  But I can't find anywhere in B1 or SQL which tells me what row number each warehouse is at. 
    Is there any other way to import into the warehouse rows?  i have tried using the warehouse code but it doesn't appear to work.
    Regards
    Jon

    Hi Johnny,
    In the oitems as you have the items, prices and warehouses CSV files.
    The LineNum for warehouse start from 0 as the order is from the warehouse setup in administration the column AF in warehouses CSV has the warehouse code, you can enter the warehouse code and then upate the entire list.
    Regards,
    Rakesh N
    Edited by: Rakesh N on Feb 21, 2010 12:19 AM
    Edited by: Rakesh N on Feb 21, 2010 12:24 AM

  • Get Rect of a line of text in text member

    hello everyone
    I need to get the top left right and bottom coordinates in
    pixels around a
    line of text in the text member where the mouse clicks.
    I know how to get the right and left positions. But top and
    botton is
    difficult.
    Any ideas and workarounds will be welcome.
    thanks
    ahmed

    Here are two links to movie which use the rect of a given
    line in a text member:
    http://nonlinear.openspark.com/tips/text/hilitetext/
    http://nonlinear.openspark.com/tips/text/multiselect/

  • How can I find out the number of lines in a text file?

    How can I find out the number of lines in a text file?

    java.io.BufferedReader in = new java.io.BufferedReader( new java.io.FileReader( "YourFile.txt" ) );
    int lineCount = 0;
    while( in.readLine() != null )
    lineCount ++;
    System.out.println( "Line Count = " + lineCount );

  • How to find number of lines in the text content?

    Hello All,
    I have a multi line text item. I want to know the number of lines in a text item? How can I do that?
    Note that every lines end with the shift+enter.
    Example,
    This is a
    sample.
    After line This is a there is (Shift + Enter).
    Thanks for any help.

    Whenever the user inputs Shift-Enter, Photoshop inserts an [EOT] (End Of Text) control character (\x03 or \u0003) in the string.
    Also, in order to split the text according to multiple separators in only one call, it is necessary to use a regular expression instead of a string.
    Try replacing:
    var theArray = theText.split("\r");
    with:
    var theArray = theText.split(/[\u0003\r]/);
    BTW, you can improve performance by explicitely requesting the textKey property of the current layer object.
    Try using:
       ref.putProperty( charIDToTypeID("Prpr"), stringIDToTypeID("textKey") );
       ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
    instead of:
       ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
    HTH...

  • Limit number of lines in a text editor

    Hello.
    In my program, i'm creating a text zone and i need to limit the data users will put in this zone.
    To create that, i'm using the object cl_gui_textedit. I've looked in the methods of this object but i wasn't able to find one that will limit the number of lines of the text editor.
    Did i miss it ? Does anybody knows how i can for example limit the input zone to 5 lines ?
    Thanks for your help.
    Here's my code
      IF g_editor IS INITIAL.
    *   Instanciation du container pour la zone de texte
        CREATE OBJECT g_textedit_custom_container
            EXPORTING
                container_name = 'TEXTEDITOR'
            EXCEPTIONS
                cntl_error = 1
                cntl_system_error = 2
                create_error = 3
                lifetime_error = 4
                lifetime_dynpro_dynpro_link = 5.
        IF sy-subrc NE 0.
    *      add your handling
        ENDIF.
    *   Création de la zone d'édition du texte
        CREATE OBJECT g_editor
          EXPORTING
            parent        = g_textedit_custom_container
            wordwrap_mode = cl_gui_textedit=>wordwrap_at_fixed_position
            wordwrap_position          = 68
            wordwrap_to_linebreak_mode = cl_gui_textedit=>true.
      ENDIF.

    I just notice there is a method SET_HEIGHT but this one is implemented in CL_GUI_CONTROL.
    I tried this :
            CALL METHOD g_editor->set_height
                    EXPORTING height = w_height.
    But in fact, i never enter the method.
    Do i have to create a CL_GUI_CONTROL object ? If yes, how do i link it to the CL_GUI_TEXTEDIT.
    Sorry if some questions mays seem obvious. It's my first object abap program.

  • Finding the number of Non-Blank Line in a File

    Does anyone know the command or how to find the number of non-blank lines in a text file? I have the program already reading characters, words, and total lines.
              BufferedReader FileIn = new BufferedReader( new FileReader( selectedFile ) );
                   Scanner scanWords = new Scanner (selectedFile);
                             String thisToken = "";
                             int numWords = 0;
                             while (scanWords.hasNext())
                             thisToken = scanWords.next();
                             numWords++;
         System.out.println("Total number of words: " + numWords);
         Scanner scanLines = new Scanner (selectedFile).useDelimiter("\n");
                             String thisToken2 = "";
                             int numLines = 0;
                             while (scanLines.hasNext())
                             thisToken2 = scanLines.next();
                             numLines++;
         System.out.println("Total number of lines: " + numLines);
         Scanner scanChars = new Scanner (selectedFile).useDelimiter("");
                             String thisToken3 = "";
                             int numChars = 0;
                             while (scanChars.hasNext())
                             thisToken2 = scanChars.next();
                             numChars++;
         System.out.println("Total number of characters: " + numChars);
                   FileIn.close();
              }

    Use BufferedReader#readLine() instead. Read the file once and process each line once.

  • How to read line number text from PDF using plugin?

    Hi, I would like to know how to read line number text from PDF using plugin?
    Thanks in advance.

    Ok, some background reading of the PDF Reference will help you understand why this is so difficult. PDF files are not organised into lines. It is best to think of each word or character on the page as being a graphic with its own position. The human eye sees lines where a series of graphics (words) are roughly in the same horizontal region.
    In the general case it is difficult or even impossible to answer this. You may have columns with different spacing (but the PDF stores no information on what is a column). You may have subscripts and superscripts. You may have text in graphics coinciding with other text. Commonly, there may be titles, headings or page numbers which are just ordinary text and might count as lines.
    That said, what you need to do is extract the text on the page and its positions. The WordFinder APIs are the way to do that. Now, sort all the words out, using the Y coordinates and size to try and guess what makes a "line". Now you are in a position to find the text (divided into words, not strings) and report the "line number" you have estimated.

  • Inserting text at a specific line number.

    Hello,
    My need is to insert specific text at a line number to be determined at run time. I know how to write to new files and append to existing ones, but I have not been able to find any documentation displaying how to traverse to a specific line in a text file. More specifically, of course I know how to use looping constructs, but I have seen no file I/O classes with a "skip line" method to get to my insertion point.
    Thank you.

    depending on the size of the files read them into a buffer use a loop to get to a specific point and write back to file.*
    Note I am sure there are many better ways to do this but this was the first thing that came to mind that would be easy for a new person to get.

  • How to find the number of fetched lines from select statement

    Hi Experts,
    Can you tell me how to find the number of fetched lines from select statements..
    and one more thing is can you tell me how to check the written select statement or written statement is correct or not????
    Thanks in advance
    santosh

    Hi,
    Look for the system field SY_TABIX. That will contain the number of records which have been put into an internal table through a select statement.
    For ex:
    data: itab type mara occurs 0 with header line.
    Select * from mara into table itab.
    Write: Sy-tabix.
    This will give you the number of entries that has been selected.
    I am not sure what you mean by the second question. If you can let me know what you need then we might have a solution.
    Hope this helps,
    Sudhi
    Message was edited by:
            Sudhindra Chandrashekar

  • How to find the number of occurance of a string in text field of Infopath form?

    Hi All,
    In Infopath text field, How to find the number of occurrence of a particular string in that field?
    Thanks in advance!

    You can check to see if it contains a string once by using the contains function, but there isn't a very clean way to do what you want. If you wanted to guess at the maximum number of occurrences, then you could:
    Box A has your initial. Set Box B to do a concat of string-before and string-after of Box A where it copies Box A minus the string we're looking for. Then we have Box C that does the same thing to Box B. Repeat as many times as you see necessary.
    Example:
    String: "1"
    Box A - "123451234512345"
    Box B - "23451234512345"
    Box C - "2345234512345"
    Box D - "234523452345"
    etc.
    We then have a field that has nested ifs looking backwards from Z -> A looking for a non-blank. Based on that, we return the number of occurrences. Again, this isn't clean, but it will work if you think there's a predefinable maximum.
    Andy Wessendorf SharePoint Developer II | Rackspace [email protected]

  • How to find the number of Z or Y programs and amount of code lines?

    hi all, I'm trying to find the number of programs on user namespace (Z* or Y*) and the number of coded lines in them. something like report Z_MY_REPORT, lines 582; Include Z_MY_INCLUDE, lines 135.
    Exist any standard report to do it or do I have to develop it by myself?
    thanks for any suggestion.

    If you have to do in urself
    DATA: i_reptx TYPE STANDARD TABLE OF textpool WITH HEADER LINE.
    READ TEXTPOOL 'ZJ_ALV' INTO i_reptx.
    and describe the itab.. and get  the lines.
    In conjunction with TADIR table to get the program repository.

  • Replacing text in Text File in a perticuler line number

    Hi,
    I have a text file where values will be stored like
    user=alex;checkout=no;checkin=yes;
    user=rexy;checkout=yes;checkin=yes;
    user=nik;checkout=no;checkin=no;
    user=philip;checkout=yes;checkin=no;
    user=nex;checkout=yes;checkin=no;
    I know the line number of user nik(no=3) how can i replace that full line only with new values
    or a particular part (checkout=yes).According to each event i have to change a specific part in text file for that user .
    Thanks
    [email protected]

    Read the first two lines and write them to a new file. Write the new values for line 3 to that new file. Read the rest of the lines and write them to that new file. Close all the files, delete the old file, rename the new file.

Maybe you are looking for

  • Creative Cloud for Higher Ed Institution

    I'd like a few questions answered on deploying Creative Cloud at a higher education institution. I need to submit a proposal to purchase the Ceative Cloud in a 20 seat lab for one year. 1. Can you tell me the price per seat for the software starting

  • Move to another computer?

    I want to purchase the Student Edition of the Creative Suite Standard on bahalf of our children (whom we homeschool).  We are starting with an older iMac (~2008) and I need to be sure that if I purchase a newer, more powerful, Mac in the future that

  • Drop-down list to trigger instance manager

    I may have bitten off more than I can chew with this one, but I have two pages. One comprises a checklist of Y/N/NA drop-downs; the other page has a repeating table row. If the drop-down selection is N I want the Instance Manager to trigger a new row

  • Get info About Interconnect in 10gR1 (10.1.0.4)

    Hallo, I need as much info as possible on cluster interconnect. I get info about OCR configuration for DATABASE cluster interconnect from $oifcfg getif and from Alert.log and querying X$KSXPIA. How can I get info about CLUSTERWARE cluster interconnec

  • Print Row Numbers and Column Letters

    How do you tell Numbers to print the Row numbers and Column letters? This was very simple in Appleworks (print dialog box had that option). Can't find it in Numbers though.