Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Get the first character in a textitem

Community Beginner ,
May 31, 2024 May 31, 2024

I'm looping through the paragraphs in a document, checking for a paragraph name, then I want to check if each new line (other than the first) starts with a specified character, if it does then I'll do other stuff, but I'm feeling dense and can't figure out how to get the first character based on what I have below. 

 

    
    var doc = app.ActiveDoc;
    var pgf = doc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;
    while(pgf.ObjectValid() === 1) {
        if (pgf.Name === 'SomePgf') {
            var textList = pgf.GetText(Constants.FTI_LineBegin);
            for (var i = 1; i < textList.length; i++) {
                // how do i get the first character of what is in the text item?
            }
        }
        pgf = pgf.NextPgfInFlow;
    }

 

 I greatly appreciate any help.

TOPICS
Scripting
386
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 31, 2024 May 31, 2024

Here is what you need:

#target framemaker

var doc, pgf, textList, count, i, firstChar;

doc = app.ActiveDoc;
pgf = doc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;
if (pgf.Name === 'SomePgf') {
    textList = pgf.GetText (Constants.FTI_LineBegin | Constants.FTI_String);
    count = textList.length;
    for (i = 0; i < count; i += 1) {
        // Test for a string.
        if (textList[i].dataType === Constants.FTI_String) {
            // Is the string at the beginning of the line?
            
...
Translate
Community Expert ,
May 31, 2024 May 31, 2024

Here is what you need:

#target framemaker

var doc, pgf, textList, count, i, firstChar;

doc = app.ActiveDoc;
pgf = doc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;
if (pgf.Name === 'SomePgf') {
    textList = pgf.GetText (Constants.FTI_LineBegin | Constants.FTI_String);
    count = textList.length;
    for (i = 0; i < count; i += 1) {
        // Test for a string.
        if (textList[i].dataType === Constants.FTI_String) {
            // Is the string at the beginning of the line?
            if (textList[i-1].dataType === Constants.FTI_LineBegin) {
                // Get the first character.
                firstChar = textList[i].sdata.slice (0, 1);
                alert (firstChar);
            }
        }
    }
}

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 01, 2024 Jun 01, 2024
LATEST

Great, thank you very much Rick!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines