Capitalize first letter of each line

Help with writing and running scripts

Capitalize first letter of each line

Postby caveatrob » Wed Jun 04, 2008 4:49 pm

Hi All,

I frequently take notes without capitalizing the first letter of each line. I'd like to do that with an UltraEdit script. How would I do so?

Thanks,

Rob
caveatrob
Basic User
Basic User
 
Posts: 20
Joined: Fri Apr 25, 2008 4:39 pm

Re: Capitalize first letter of each line

Postby mjcarman » Wed Jun 04, 2008 8:22 pm

You don't need a script. A search and replace will do it just as well (and faster).
Find What: ^(\s*\w)
Replace With: \U$1

Be sure to check Regular Expressions and select Perl as the regex engine.

Since it sounds like you'll want to use it regularly you can run it from a macro:
Code: Select all
InsertMode
ColumnModeOff
HexOff
PerlReOn
Find RegExp "^(\s*\w)"
Replace All "\U$1"
User avatar
mjcarman
Power User
Power User
 
Posts: 123
Joined: Thu Feb 10, 2005 12:00 am

Capitalizing the first letter of each line

Postby caveatrob » Tue Jun 10, 2008 9:38 am

Hi all,

I've got a script that I modifed from a Macro to capitalize the first letter of each line. It doesn't seem to do -- anything.

Any ideas?

Code: Select all
    // Is any file currently open?
   
       UltraEdit.ueReOn();
       UltraEdit.activeDocument.hexOff();
       UltraEdit.activeDocument.bottom();
       // Is the last line of the file terminated with a line ending?
       if (UltraEdit.activeDocument.isColNumGt(1)) {
          // No, insert missing line ending (DOS, UNIX or MAC).
          UltraEdit.insertMode();
          UltraEdit.columnModeOff();
          UltraEdit.activeDocument.insertLine();
          // If auto indent is enabled and last line starts with white-spaces,
          // delete the automatically inserted white-spaces in the new last line.
          if (UltraEdit.activeDocument.isColNumGt(1)) {
             UltraEdit.activeDocument.deleteToStartOfLine();
          }
       }
       UltraEdit.activeDocument.top();
       
       
       UltraEdit.activeDocument.findReplace.mode=0;
       UltraEdit.activeDocument.findReplace.searchDown=true;
       UltraEdit.activeDocument.findReplace.matchCase=false;
       UltraEdit.activeDocument.findReplace.matchWord=false;
       UltraEdit.activeDocument.findReplace.regExp=true;
       UltraEdit.activeDocument.findReplace.replaceAll=true;
       
       
       UltraEdit.activeDocument.findReplace.replace("^(\s*\w)","\U$1");
caveatrob
Basic User
Basic User
 
Posts: 20
Joined: Fri Apr 25, 2008 4:39 pm

Re: Capitalizing the first letter of each line

Postby jorrasdk » Tue Jun 10, 2008 10:00 am

Business as usual: Backslashes must be escaped in strings in javascript:

UltraEdit.activeDocument.findReplace.replace("^(\\s*\\w)","\\U$1");

and you are using Perl regexp, so add UltraEdit.perlReOn();
User avatar
jorrasdk
Master
Master
 
Posts: 275
Joined: Mon Mar 19, 2007 11:00 pm
Location: Denmark

Re: Capitalizing the first letter of each line

Postby caveatrob » Tue Jun 10, 2008 12:40 pm

That was it. Thank you very much! Has anyone given a thought to a wiki for UltraEdit scripts? I'd be happy to help putting it together.
caveatrob
Basic User
Basic User
 
Posts: 20
Joined: Fri Apr 25, 2008 4:39 pm


Return to Scripts