Copy link to clipboard
Copied
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.
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?
...
Copy link to clipboard
Copied
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);
}
}
}
}
Copy link to clipboard
Copied
Great, thank you very much Rick!