How to get the string contents of itemByRange?

Hi all

Here's what I'm trying to achieve:

I selected a Word and you want to get the content of the 1st word in the string (the name of a person).

1.png

In fact, the selected text is the source * a hyperlink and my goal is to get the name of the person designated by him.

[0] is the same as hyperlink.source.sourceText

Since I can not get the paragraph or line where the selected word is (or simply do not know how to do this), I'm trying to get the full story: from the 1st character of the selected word and moving backward character by comparing its content. When it hits '\r', I know it's the beginning of the line. This way I can get the part of the line, I'm interested with the itemByRange() method, which returns "Array of Character."

Main();

function Main() {
    var doc = app.activeDocument;
    var sel = app.selection[0];

    GetName(sel);
}

function GetName(txt) {
    var lastCharacter = txt.characters[0];
    var character = txt.characters[0];
    var story = txt.parentStory;
    var index = lastCharacter.index;

    while (character.contents != "\r") {
        character = story.characters[index];
        index--;
    }

    // Array of Character itemByRange (from: varies, to: varies)
    // Returns the Characters within the specified range. 
    var arr = story.characters.itemByRange(character, lastCharacter);

    var str1 = arr.contents[0];
    var str2 = str1.match(/^\S+/);

    return str2;
}

My problem is that I can't get the content- str1 - by script. However, I can see in the data browser that it is there. If I click on str1, it appears:

2.png

If I type str1 in the Console, I also get:

3.png

I also tried to use:

arr.getElements)

arr.getElements () [0]

.silence arr.getElements () [0]

etc.

but that didn't work either.

I must be missing something very obvious, but I'm stuck. Can someone help me, please?

Kind regards

Kasyan

Hello

I did something wrong or

App.Selection [0]. Lines [0]. Words [0] .silence

is a 1 Word, you are looking for?

I hope that...

Tags: InDesign

Similar Questions

  • How to get the string (specified by row and column) of txt file with labview

    Hello world

    How to get the string (specified by row and column) of txt file with labview

    THX

    As far as I know, a text file has no column.  Be more specific.  Do you mean something like the 5th word on line 4, where the words are separated by a space, and lines are separated by a newline character?  You can read from the spreadsheet String function and set the delimiter to a space.  This will produce a 2D channels table.  Then use the table to index and give the line number and column number.

  • How to get the part of string before and after a character

    Hi all

    How to get the string before and after the comma character)

    Ex: The string contains the value John Kennedy

    I need the output as first stirng - John

    Second stirng - Kennedy

    Create table names (fullname varchar2 (20));

    insert into values of names ("John, Kennedy");

    insert into values of names ("papa ibra, Shan");

    insert into values of names ('Don Bosco'),

    Select * from names;

    Expected results

    FullName firstname lastname

    John, Kennedy John Kennedy

    Nicolas, Nicolas Shan Shan

    Don Bosco Don Bosco

    Please let me know how to proceed

    Thank you

    Hello

    This proves what I said before, on 0 and several commas commas.

    If we add these 3 rows to the sample data you posted:

    insert into names (fullname) values ("tou").

    insert into names (fullname) values (' David, Lloyd, George ");

    insert into names (fullname) values ('J, R, R, Tolkien");

    then the query I posted earlier produced these results:

    FULLNAME FIRSTNAME LASTNAME

    -------------------- -------------------- --------------------

    John, Kennedy John Kennedy

    Nicolas, Nicolas Shan Shan

    Don Bosco Don Bosco

    TOU tou

    David Lloyd, George David Lloyd, George

    J, R, R, Tolkien J R, R, Tolkien

    If you prefer to get these results:

    FULLNAME FIRSTNAME LASTNAME

    -------------------- -------------------- --------------------

    John, Kennedy John Kennedy

    Nicolas, Nicolas Shan Shan

    Don Bosco Don Bosco

    TOU tou

    David Lloyd, George David, Lloyd George

    J, R, R, J, R, R Tolkien Tolkien

    then you just change line 1:

    WITH got_commapos AS

    (

    SELECT FullName

    , INSTR (fullname, ','-1) AS commapos-* CHANGED *.

    Names

    )

    SELECT FullName

    , SUBSTR (fullname, commapos 1, -1) AS a first name

    SUBSTR (fullname, commapos + 1) in the FORM name

    OF got_commapos

    ;

  • How to get the value of a variant as a string

    I have an existing codebase, which transmits the values of the user interface to business logic as variants. I was prompted to connect all values passed in this way in a text file. I'm trying to figure out how to get the data as a string to a Variant value without having to deal on the type for the data descriptor. The flag variant the fact, so I think I can, too.

    Anyone know how?

    Thank you, all! I decided to use the XML approach:

  • How to get the number of line of a multi-line string

    It seems that this Panel of string does not provide the tool to get the chain line number,

    Does anyone have the same experience?

    so...

    How to get the line number of a variable string?

    Number of lines

  • How to get the decimal value of a string of international currency

    Hi all

    How to get the decimal values to a string of international currency.

    Finally, we get to the real problem.

    You can use location functions or write your own using string functions already mentioned...

    http://developer.BlackBerry.com/native/documentation/Cascades/device_platform/internationalization/

  • How to get the content during execution classpath

    In production mode, I can't stop the weblogic server. In the command line window, shows that recent information. How to get the content of the classpath of weblogic domain?

    You can view the log file of the server under the location */servers//log / *. The log file contains the details about the CLASSPATH setting.

    A typical classpath is represented by the java.class.path attribute in the log file.

    See you soon,.
    Julien
    http://WebLogic-wonders.com

  • How to get the content incorporate the swf file in Swf Loader on the run time

    How to get the content incorporate the swf file in Swf Loader on the run time

    [Bindable]

    [Embed(source="assets/index.swf")]

    private var SWFSRC: Class;

    < mx:SWFLoader id = "_swfloader" source = "{SWFSRC}" / >

    It might be Loader (DisplayObjectContainer (_swfLoader.content) .getChildAt (0)) content

  • How to get the text formatting in the tables

    Dear experts and aid

    For my project, I import an RTF file and then read the data into 3 tables. It works fine when just using the contents of the string of paragraphs. However, the final script should be able to read and to replace the text formatted...
    Why use intermediate tables? Because otherwise I need to swap between two fm-documents (and you can be a part of the book).

    The imported file starts with a certain number of lines separated into two parts by a TAB ("designates a TAB in \x08 FM)
    [[Garneau, 1990 #12]]    »   [9]
    The good article can also be locally as text, e.g. [9]
    Then follow the same (or smaller) number of paragraphs with text formatted like this:
    [9]"D. Garneau, ed., National Language Support Reference Manual (national language Information Design Guide. Toronto, CDN: IBM National Language technical Centre, 1990.

    Is it possible to replace in the body of the function below the next song

      while(pgf.ObjectValid()) {
        pgfText = GetText (pgf, newDoc);
        gaBibliography.push(pgfText);
        pgf = pgf.NextPgfInFlow;
      }
    

    with this

      while(pgf.ObjectValid()) { 
        gaBibliography.push(pgf);
        pgf = pgf.NextPgfInFlow;
      }
    

    Do I need a special statement of the gaBibliography range?
    And how to get the right part of the lines as formatted intro thingy in table gaFmtCitsFmt ?

    Currently, I read in the tables as "strings" (function GetText not shown):

    var gaFmtCitsRaw  = [];                           // left column in processed RTF
    var gaFmtCitsFmt  = [];                           // right column in processed RTF
    var gaBibliography= [];                           // bibliography lines from processed RTF
    // filename is something like E:\_DDDprojects\FM+EN-escript\FM-testfiles\BibFM-collected-IEEE.rtf 
    
    function ReadFileRTF (fileName) {
      var nCits=0, nBib = 0, openParams, openReturnParams, newDoc, pgf, pgfText ;
      var TAB = String.fromCharCode(8);               // FM has wrong ASCI for TAB
      var parts = [];
      
      openParams = GetOpenDefaultParams();
      openReturnParams =  new PropVals();  
      newDoc = Open (fileName, openParams, openReturnParams);  
      pgf = newDoc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;  // get first pgf in flow
    
    // --- read the temp/formatted citations  
      while(pgf.ObjectValid()) {
        pgfText = GetText (pgf, newDoc);
        if (pgfText.substring (0,2) == "[[") {        // citation lines start with [[
          parts = pgfText.split(TAB);                 // get the two parts of the line
          gaFmtCitsRaw.push (parts[0]);               // Push the result onto the global array
          gaFmtCitsFmt.push (parts[1]);
          pgf = pgf.NextPgfInFlow;
        } else { break }
      }
    
    // --- read the bibliography
      while(pgf.ObjectValid()) {                      // until end of doc
        pgfText = GetText (pgf, newDoc);
        gaBibliography.push(pgfText);
        pgf = pgf.NextPgfInFlow;
      }
      newDoc.Close (Constants.FF_CLOSE_MODIFIED);
    } // --- end ReadFileRTF
    

    The following questions will then be how to change the script of FindAndReplace of Ian Proudfoot for managing text formatted as replacement. I will need to use the copy and paste IMHO...

    Klaus, okay, before pasting, you must assign the TextSelection object at your insertion point.

    // Add a new paragraph after the current paragraph.
    var newPgf = oDoc.NewSeriesPgf (lastPgf);
    var textRange = new TextRange (new TextLoc (newPgf, 0), new TextLoc (newPgf, 0));
    
    oDoc.TextSelection = textRange;
    oDoc.Paste ();
    

    -Rick

  • How to get the value of a selected character unicode?

    Hi all

    How to get the value of a selected character unicode?

    The content property of a 'Character' InDesign object is a simple Unicode string. For access to the various characters is a basic javascript operation, and a google gives this as a good first result: http://www.w3schools.com/jsref/jsref_charCodeAt.asp

    Therefore, the value of a selected character unicode is

    App.Selection [0]. Characters [0].contents.charCodeAt (0)

  • How to get the video intro off my google home screen I already saw it, where is the firefox logo used to be.

    How to get the video intro off my google home screen I already saw it, where is the firefox logo used to be. I started with the last update that I rebooted.

    Hello
    to change the homepage when opening firefox-press 'Alt' and click on tools-> Options.

    Main menu, you can change the URL.

    If the problem persists, you can follow these simple steps:

    Enter about: config in the address bar and press ENTER. Accept the message of 'dragons' to see the Advanced preferences screen. Use the above search box to enter the below pref.

    You can assign an empty string to stop your Firefox to retrieve "extracts" and brandLogo changes the browser.aboutHomeSnippets.updateUrl pref. Right-click this pref and select Edit then clear the value as pref in the box that appears, and then click OK. Who will also disable "snippets" that appear under the container of the research on the default home page.

    Then you must open the folder of your profile, via help > Troubleshooting Information > profile folder > > button view folder. Then close Firefox. Your profile file open with Firefox closed (Firefox '3-bar' menu key > exit/Quit), wait or two minutes, then remove the storage\moz-safe-about + home folder in the Firefox profile folder to remove the brandLogo and stored in IndexedDB code snippets to make Firefox use the default brandLogo and a defined default code snippet.

    If you later change your mind about these changes, you can reset the pref browser.aboutHomeSnippets.updateUrl via the context menu and Reset allows to retrieve the default value using the storage\moz-chest-fort-about + home folder again.

  • How to get the return parameter in sequence teststand ran by labview labview

    Hello

    Executes a test sequence of labview (essentially running "\Examples\TestStand API\Executing sequences using API\LabVIEW\Execute with no Model.vi process") I need to get a parameter returned in 'Settings', after the sequence has run.

    My problem is that I get the value upon registration of the sequence and not the value after execution.

    How?

    Vagn

    Vagn,

    in order to obtain the values of the execution, you need access to execution. The following screenshot shows how to access.

    Please note that this VI is lying will be called by TestStand. DO NOT USE THIS VI IN A CUSTOM USER INTERFACE!

    Thank you

    Norbert

    EDIT: This dummy code shows how to read the string parameter 'Return '. Each parameter must be read separately with appropriate playback function.

  • How to get the bar display of title in pixels text length?

    Hello

    Does anyone know how to get the length of the title bar text (in pixels) display?  Just to clarify, that's what I'm looking for:

    I don't see a CVI function for this.  The attribute ATTR_TITLE_FONT for GetPanelAttribute (...) is only valid for the panels of the child which prevents me from using the GetTextDisplaySize (...) to get the size.  Dive into the Windows SDK I can not even find an answer here.  Any ideas?  Thank you.

    Figured out how to do this.  Go to the SDK to get the font properties - is kind of nonobviousness.  But once you have the font properties, you can create a font of meta in CVI, with properties, and once you have the meta font you can use GetTextDisplaySize (...) to get the size.  For any future reference:

    //define a NONCLIENTMETRICS structureNONCLIENTMETRICS ncmtest;//We have to set the cbSize parameter to the size of the passed structure before retrieving it
    ncmtest.cbSize = sizeof(NONCLIENTMETRICS);
    //Get NONCLIENTMETRICS structure
    result = SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncmtest, 0);
    
    //copy the title font name to a c-string
    while(ncmtest.lfCaptionFont.lfFaceName[i] != 0)
    {
        thefont[i] = (char)ncmtest.lfCaptionFont.lfFaceName[i];
        ++i;
    }
    
    //null terminate
    thefont[i] = '\0';
    
    //create meta font with title font properties.  lfWeight & 0x700 indicates bold.  CreateMetaFontWithCharacterSet() doesn't recognize DEFAULT_CHARSET so we replace it with VAL_NATIVE_CHARSET(?).
    uir_status = CreateMetaFontWithCharacterSet ("TheTitleFont", thefont, abs(ncmtest.lfCaptionFont.lfHeight), ncmtest.lfCaptionFont.lfWeight & 0x700 ? 1 : 0, ncmtest.lfCaptionFont.lfItalic, ncmtest.lfCaptionFont.lfUnderline, ncmtest.lfCaptionFont.lfStrikeOut, 0, ncmtest.lfCaptionFont.lfCharSet == DEFAULT_CHARSET ? VAL_NATIVE_CHARSET : ncmtest.lfCaptionFont.lfCharSet);
    
    //get titlebar text
    uir_status = GetPanelAttribute (panelhandle, ATTR_TITLE, thetext);
    //get title bar length
    uir_status = GetTextDisplaySize (thetext, "TheTitleFont", &height, &width);
    

    I have a 79 for the duration of the screenshot above.

  • How to get the maximum number of iterations in the property of TS

    I was put the loopType from one step to the count of success/failure. For example "stop after 1 iterations pass or a maximum of 3 iterations. The maximum iteration is 3. What my qustion is how to get the maximum iteration of TS property by codes of trial during the race. Thank you very much!

    Corey Chen

    The OPPO test developer

    Hello

    It may be a hack, but RunState.Step.LoopWhileExpression has information.  It will return a string like: "RunState.LoopIndex."< 69="" &&="" runstate.loopnumpassed=""><>

  • Get the binary content of a file

    Hello

    can someone help me get the binary content to the format string of any file passed as an input.

    IM new to the Blackberry Java development so please help me with this.

    Any help would be appreciated.

    Thank you & best regards

    I found the solution.

    I used two different functions to get the binary and hexadecimal representation respectively

    These two functions are:

    
    // function that returns binary data of file
    
    public String getBits(byte b)
        {
            String result = "";
            for(int i = 0; i < 8; i++)
                result += (b & (1 << i)) == 0 ? "0" : "1";
            return result;
        }
    
    // function that returns hex data of a file and writes it to another file
    
        public static String byteArrayToHexString(byte[] b) {
    
            int len = b.length;
            char[] s = new char[len * 2];
    
            for (int i = 0, j = 0; i < len; i++) {
              int c = ((int) b[i]) & 0xff;
    
              s[j++] = (char) HEXBYTES[c >> 4 & 0xf];
              s[j++] = (char) HEXBYTES[c & 0xf];
            }
    
            DataOutputStream os = null;
            FileConnection fcon = null;
            try {
    fcon = (FileConnection)Connector.open("file:///store/home/user/hexfeatures.txt",Connector.READ_WRITE);
    
                fcon.create();
                os = fcon.openDataOutputStream();
                os.writeChars(new String(s));
    
                os.close();
                fcon.close();
    
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    
            return new String(s);
          }
    

    Thank you & best regards

Maybe you are looking for

  • Tecra 9000 - WLan and new hardware issue

    I have a 2nd hand Tecra 9000 that works all fine except the WlanAlso the new hardware wizard (perhaps related) keeps poping up.1. WLan Bluetooth.the computer labels proclaim inside the WiFi or Bluetooth.* There is a Wlan switch that illuminates an in

  • Satellita C660-13 q PSC0QE - problems identify the correct driver

    Hi all! I have a Toshiba Satellite C660-13 q (init p.n. PSC0QE). After a hard drive failure, I replace the HD toshiba and I tried to install Windows 7 Ultimate 32 bit. I don't have many problems with the exception of two system devices to identify: C

  • Fix utility wipe original programs on Satellite L300D?

    Sorry, this is a repost of a previous question, but this time I will keep it very short.I have no answer, and maybe it's because my message was too long. Whenever I have download anything, my L300D tells me that the file is corrupted. Unless I can fi

  • Satellite L40 - 12 k WinXP - cannot change the brightness of the display

    Got Toshiba Satellite l40 - 12 k laptop.Running Windows XP Pro. The problem is that I can not change the brightness of the display even with hotkey utility for Win Vista installed. But if I'm in the bios of these keys work fine. Even when I started t

  • Venue 11 Pro keyboard

    We recently purchased several new sites with keyboards. I noticed that keyboards have a charging port, but it is physically impossible to access when it is connected to the room. My question is... If the place is actively supported, is the keyboard i