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?
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?
var s = "Hello";var replace_char = "p"; // Replace the last characters = s.slice(0, -1) + replace_char; app.alert(s); // Should display "Hellp"
var s = "Hello"; // Trim off the last characters = s.slice(0, -1); app.alert(s); // Should display "Hell"
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];}
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];}
The "slice" string method is documented in your new JavaScript reference book.
George