Hello. Can you help me with a script.
In your programm is the script that delete all spaces in the end of lines. How can I do this with the startspaces?
Sorry for my English. Hope you understand me.
Help with script
Re: Help with script
Do you need a script for this (to be able to run it e.g. on each file open or save), or do you need it just one time? Because if the latter, you can simply select all text (Ctrl-A) and hit Shift-Tab a couple of times.
Alium tibi quaere fratrem; hic, quem tuum putas, meus est. Titus Flāvius Caesar Vespasiānus Augustus
- Rickard Johansson
- Site Admin
- Posts: 6661
- Joined: 19 Jul 2006 14:29
Re: Help with script
Try this
(Edited once to add try..finally block.)
Code: Select all
// C++ script
{
string s;
int i,n;
int startx,startLine,endx,endLine;
if (Document.SelLength > 0) {
Document.GetSelection(startx,startLine,endx,endLine);
} else {
startLine = 0;
endLine = Document.LineCount - 1;
};
Document.BeginUpdate();
try
{
i = startLine;
while (i <= endLine) {
// Get line from document
s = Document.Lines[i];
// Remove spaces and write back modified line
n = 0;
while ((n <= Length(s)) && (ScriptUtils.PosAt(" ",s,n+1))) { n++; };
if (n > 0) {
// Remove spaces
Delete(s,1,n);
// Write modified line to document
Document.Lines[i] = s;
};
i++;
};
}
finally
{
Document.EndUpdate();
};
}
Re: Help with script
OK, since you need a script, here's one for you; enjoy!
Code: Select all
// JScript
// turn off screen updating
Document.BeginUpdate();
// turn word-wrap off
if (Document.Wordwrap) {
Document.Wordwrap = false;
}
// remove leading spaces
for (var i = 0; i < Document.LineCount; i++) {
Document.Lines[i] = ScriptUtils.RegExReplaceAll(Document.Lines[i], "^\\s+", "");
}
// turn on screen updating
Document.EndUpdate();
Alium tibi quaere fratrem; hic, quem tuum putas, meus est. Titus Flāvius Caesar Vespasiānus Augustus
Re: Help with script
Thank you! The second script works perfectly.
Re: Help with script
You are very welcome! I'm glad I could help
Alium tibi quaere fratrem; hic, quem tuum putas, meus est. Titus Flāvius Caesar Vespasiānus Augustus