Something like this?
for (a=2; a<app.activeDocument.allParagraphStyles.length; a++) app.activeDocument.allParagraphStyles[a].name = app.activeDocument.allParagraphStyles[a].name.replace(/ /g, '_'); for (a=1; a<app.activeDocument.allCharacterStyles.length; a++) app.activeDocument.allCharacterStyles[a].name = app.activeDocument.allCharacterStyles[a].name.replace(/ /g, '_');
The first one starts at index #2 because it needs to skip "[No Paragraph Style]" and "[Basic Paragraph]", the second one only needs to skip "[None]".
That was amazing! It works!!!! Thanks soooooo much!!!!!
Followup questions..... the reason why I have to cleanup all of the styles names is because I need to export the text as XML.
In my style names, I still have some questionable characters: hyphens (-), slashes (/), parentheses () and periods (.)
1) If these need to be changed (not sure if any of these need to be changed), what is the code for these characters so I can replace them with underscores?
2) I then will need to replace multiple underscores (2 or 3 in a row) with a single underscore...
Is this code below correct for #2? (run it twice?)
for (a=2; a<app.activeDocument.allParagraphStyles.length; a++)
app.activeDocument.allParagraphStyles[a].name = app.activeDocument.allParagraphStyles[a].name.replace('_''_', '_');
3) The most annoying thing that I'm finding in these documents that I have to clean up is that they used the Basic Paragraph style for a lot of the text rather than an actual created style. I'm assuming that a simple Find/Replace should take care of that once I create a new style.
This should work -- but, rather then the above code, this is untested:
.. replace (/[- \/()\._]+/g. "_");
Well, this replace string comes with a free bonus. Note the + sign after the OR-group. This means that an entire sequence of these characters will be replaced with a single underscore: "This is /a-/ test" will become "This_is_a_test". Adding the underscore itself to the find string means that it will also find the entire string "space ( underscore ) space" in "This (_) style" and, oh magic!, replace it immediately with a single underscore.
Just FYI, the lowercase 'g' after the closing slash is short for 'global', that is, globally replacing in this string. replace defaults to one replacement only (why? see above ...), and adding the 'g' ensures it keeps replacing until it doesn't find any matches anymore.
2. See point 1.
3. Erm, yes that's right, but you will need to check very carefully if nothing inside any of those Basic styles is overridden. You can apply a Basic style and add overrides to make it look like a Subheading, but that doesn't make it one. And for the next paragraph, you can apply a Basic style and add overrides to make it look like a plain text paragraph (etc.). It is a telltale signature of bad formatting ...
Thanks again!!! it worked!!!
And thanks for explaining the code to me as well!