These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Finding nth letter

Duniagdra
Registered: Sep 24 2008
Posts: 140
Answered

I've been reading and searching, but I'm coming up short. Is there a method for finding the last letter of a word and replacing or removing it?

Thanks in advance for any help provided,
Jim
The All Time Professional Amateur Hack

My Product Information:
Acrobat Pro 8.1, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
There a many ways. Here's one:

var s = "Hello"; // Trim off the last characters = s.slice(0, -1); app.alert(s); // Should display "Hell"

The "slice" string method is documented in your new JavaScript reference book.

George
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Oh, and to replace the last character you could do something like:
var s = "Hello";var replace_char = "p"; // Replace the last characters = s.slice(0, -1) + replace_char; app.alert(s); // Should display "Hellp"
Duniagdra
Registered: Sep 24 2008
Posts: 140
George_Johnson wrote:
There a many ways. Here's one:
var s = "Hello"; // Trim off the last characters = s.slice(0, -1); app.alert(s); // Should display "Hell"

The "slice" string method is documented in your new JavaScript reference book.

George
Thanks George for your assist.

Here's what I tried:
var oASRTB = {Dragonborn1: [2, "", "", "", "", 2,"Common, Draconic"],Dwarf: ["", 2, "", "", 2, "","Common, Dwarven"],Eladrin: ["", "", 2, 2, "", "","Common, Elven"],Elf: ["", "", 2, "", 2, "","Common, Elven"],Half_Elf: ["", 2, "", "", "", 2,"Common, Elven"],Halfling: ["", "", 2, "", "", 2,"Common"],HumanS: [2, "", "", "", "", "","Common"],HumanC: ["", 2, "", "", "", "","Common"],HumanD: ["", "", 2, "", "", "","Common"],HumanI: ["", "", "", 2, "", "","Common"],HumanW: ["", "", "", "", 2, "","Common"],HumanH: ["", "", "", "", "", 2,"Common"],Tiefling: ["", "", "", 2, "", 2,"Common"],}; app.popUpMenuEx({cName:"Dragonborn",cReturn:"Dragonborn"},{cName:"Dwarf", cReturn:"Dwarf"},{cName:"Eladrin", cReturn:"Eladrin"},{cName:"Elf", cReturn:"Elf"},{cName:"Half Elf", cReturn:"Half_Elf"},{cName:"Halfling", cReturn:"Halfling"},{cName:"Tiefling", cReturn:"Tiefling"},{cName:"Human",oSubMenu:[{cName:"Strength",cReturn:"HumanS"},{cName:"Constitution", cReturn:"HumanC"},{cName:"Dexterity", cReturn:"HumanD"},{cName:"Intelligence", cReturn:"HumanI"},{cName:"Wisdom", cReturn:"HumanW"},{cName:"Charisma", cReturn:"HumanH"}], }); if(strResult != null){if(strResult.slice(0, -1) == "Human"){getField("Race").value = strResult.slice(0, -1);getField("Race").value = strResult;}//"HumanC" || "HumanD" || "HumanI" || "HumanW" || "HumanH"))getField("Ability_STR_Race").value = oASRTB[strResult][0];getField("Ability_CON_Race").value = oASRTB[strResult][1];getField("Ability_DEX_Race").value = oASRTB[strResult][2];getField("Ability_INT_Race").value = oASRTB[strResult][3];getField("Ability_WIS_Race").value = oASRTB[strResult][4];getField("Ability_CHA_Race").value = oASRTB[strResult][5];getField("LangBasrRace").value = oASRTB[strResult][6];}

Nothing happens at all though. I'm trying to drop the last letter only if human is selected. I'm not finding a solution in the book you recommended other than .slice() and .shift. Any suggestions?

Again, thanks for your time in helping with this.
Jim

Thanks in advance for any help provided,
Jim
The All Time Professional Amateur Hack

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
My guess is that you mean to do the following:


var oASRTB = {Dragonborn1: [2, "", "", "", "", 2,"Common, Draconic"],Dwarf: ["", 2, "", "", 2, "","Common, Dwarven"],Eladrin: ["", "", 2, 2, "", "","Common, Elven"],Elf: ["", "", 2, "", 2, "","Common, Elven"],Half_Elf: ["", 2, "", "", "", 2,"Common, Elven"],Halfling: ["", "", 2, "", "", 2,"Common"],HumanS: [2, "", "", "", "", "","Common"],HumanC: ["", 2, "", "", "", "","Common"],HumanD: ["", "", 2, "", "", "","Common"],HumanI: ["", "", "", 2, "", "","Common"],HumanW: ["", "", "", "", 2, "","Common"],HumanH: ["", "", "", "", "", 2,"Common"],Tiefling: ["", "", "", 2, "", 2,"Common"],}; var strResult = app.popUpMenuEx({cName:"Dragonborn",cReturn:"Dragonborn"},{cName:"Dwarf", cReturn:"Dwarf"},{cName:"Eladrin", cReturn:"Eladrin"},{cName:"Elf", cReturn:"Elf"},{cName:"Half Elf", cReturn:"Half_Elf"},{cName:"Halfling", cReturn:"Halfling"},{cName:"Tiefling", cReturn:"Tiefling"},{cName:"Human",oSubMenu:[{cName:"Strength",cReturn:"HumanS"},{cName:"Constitution", cReturn:"HumanC"},{cName:"Dexterity", cReturn:"HumanD"},{cName:"Intelligence", cReturn:"HumanI"},{cName:"Wisdom", cReturn:"HumanW"},{cName:"Charisma", cReturn:"HumanH"}], }); if(strResult != null){if(strResult.slice(0, -1) == "Human"){getField("Race").value = strResult.slice(0, -1);} else {getField("Race").value = strResult;}//"HumanC" || "HumanD" || "HumanI" || "HumanW" || "HumanH"))getField("Ability_STR_Race").value = oASRTB[strResult][0];getField("Ability_CON_Race").value = oASRTB[strResult][1];getField("Ability_DEX_Race").value = oASRTB[strResult][2];getField("Ability_INT_Race").value = oASRTB[strResult][3];getField("Ability_WIS_Race").value = oASRTB[strResult][4];getField("Ability_CHA_Race").value = oASRTB[strResult][5];getField("LangBasrRace").value = oASRTB[strResult][6];}

George
Duniagdra
Registered: Sep 24 2008
Posts: 140
Niiiice! Thanks George.

Thanks in advance for any help provided,
Jim
The All Time Professional Amateur Hack