You can feed the sort() method a function like so: string.sort(function)
This allows you to sort based on whatever criteria you want.
In your case, the standard sort() will work just fine to sort in the
order you want. However you might want to change the alphabetical
sorting with capitals and lowercase...
If I understand you correctly, I don't think that's what I need to do.
Perhaps more informating is needed. The point of the larger script is to allow me to create a number of entries from a single selection. I select a recipe title, and run the script. It creates a dialog that has two text boxes, one for the entry and another for the 'sort as.' Below that are a lot of checkboxes. The checkboxes allow me to select alphabetical, some categories ('Desserts,' 'Entrées,' etc.) and some ingredients ('Broccoli,' 'Salmon,' etc.). I select those that apply to that recipe and click OK.
The script then creates entries for each box checked, putting the recipe name at level two, and the checkbox name as level 1. Alphabetical entries get the first letter of the Sort As text entry as thier level 1, and a pound sign as the sort as attribute. The categories are given a dollar sign in thier Sort As attribute, and the ingredients sort as normal. Then, when I generate my index, I get all the recipe names in alphabetical order, followed by the categories and the recipes in them, and lastly the ingredients with the recipes that contain them. 3 indexes in one.
Except that certain recipes are sorted wrong in the index. So I'd like to force the index feature of InDesign to treat them right by changing the Sort As attribute.
But you don't really need to know any of this. I just include it in case the concrete reason for my need is unclear.
All I need to know is how to take a variable that contains a text string and change some of the characters to something else. In other words, how do I deal with the parts of a string, rather than the whole string as one entity.
Edit: error in code
myString = myString.replace (" ", "1")
Other useful string functions are .slice (), .search(), and .indexOf(). And as Michael mentioned, learning some basic regular expressions is well worth the effort.
Thanks. That's exactly what I need.
Guess I have to get myself a good book if I want to get any better. I think I've just about learned all I'll be able to from the PDF manuals Adobe provides.