 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
WhiteCloud
Joined: 19 Jun 2004 Posts: 68
|
Posted: Sat Jul 03, 2004 4:42 am Post subject: detecting linefeeds as opposed to carriage returns in a file |
|
|
in ahk it doesn't save the linefeeds or the carriage returns into a variable when it does a file loop right? How can I detect which one is there? _________________ AHK = Hella fun |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Sat Jul 03, 2004 12:14 pm Post subject: |
|
|
The short answer is that there is no way to do it. I could add the asterisk feature to the input file if you're sure you need this.
Background: The way it stands now, a `r`n pair in the file is translated to a single `n by Windows when you read the file. That `n is removed by the file-reading loop, so you don't see it. I believe this same process is used if the file contains only naked `n terminators rather than `r`n. I also believe that files containing only `r (Macintosh) aren't read in correctly by most programs, including AHK.
Although all standard Windows text files have `r`n terminating their lines, when writing a text file (with FileAppend), you should use only `n because Windows automatically translates that to `r`n when the text file is written. The only exception to this is when using the asterisk in front of the OutputFile, which writes in binary mode as described in the help file. The asterisk is useful to create Unix text files. |
|
| Back to top |
|
 |
Beastmaster
Joined: 15 Apr 2004 Posts: 182
|
Posted: Sat Jul 03, 2004 2:14 pm Post subject: |
|
|
Would it be possible to pipe the complete text to the clipboard (and keep the line endings, correct me if I'm wrong ) and than check the CLIPBOARD variable for that character ?
____________________
If only a visible check is possible - Notepad2 provides an option to show line ending characters and swap them with a "single" click.
ALT+F+[W=CRLF ; U=LF ; M=CR]
-----
Installation and Uninstallation
Just put a copy of Notepad2.exe to any directory on your computer. To
remove the Notepad2 registry entries, run "Notepad2.exe -u" from any
command line, and then delete Notepad2.exe to have a complete,
traceless uninstall.
Keyboard Shortcuts for Notepad2
File
Ctrl+N New file.
Ctrl+F4 Close file, identical with Ctrl+N.
Ctrl+O Open file.
F5 Reload file.
F8 Reload file without encoding detection.
Ctrl+S Save file.
F6 Save file as.
Ctrl+F6 Save file copy.
Ctrl+P Print file.
Alt+H Open recent file.
Tools
Alt+N Open document in new window.
Alt+0 Open new empty window.
Ctrl+M Run metapath file browser plugin.
Ctrl+L Launch document.
Alt+L Open with.
Ctrl+Q Run command.
Favorites
Alt+I Open favorites.
Alt+K Add to favorites.
F9 Manage favorites.
Edit
Ctrl+Z Undo.
Alt+Backspace Undo.
Ctrl+Y Redo.
Ctrl+X Cut.
Shift+Del Cut.
Ctrl+C Copy.
Alt+C Copy all.
Ctrl+V Paste.
Shift+Ins Paste.
Del Clear.
Ctrl+A Select all.
Alt+Shift+Arrows Rectangular selection.
Ctrl+Enter New line with toggled auto indent option.
Ctrl+PgUp/PgDn Goto previous/next block.
Ctrl+Shift+PgUp/PgDn Select to previous/next block.
Word
Ctrl+Space Select word.
Ctrl+Backspace Delete word before/left.
Ctrl+Del Delete word after/right.
Line
Ctrl+Shift+Up Move line up.
Ctrl+Shift+Down Move line down.
Ctrl+T Transpose line.
Ctrl+D Duplicate line.
Ctrl+Shift+X Cut line.
Ctrl+Shift+C Copy line.
Ctrl+E Delete line.
Ctrl+Shift+Backspace Delete line left.
Ctrl+Shift+Del Delete line right.
Block
Tab Indent selected block.
Shift+Tab Unindent selected block.
Alt+Z Strip first character.
Alt+W Strip trailing blanks.
Alt+R Remove blank lines.
Ctrl+I Split lines.
Ctrl+Shift+I Join lines.
Brace
Ctrl+B Find matching brace.
Ctrl+Shift+B Select to matching brace.
Convert
Ctrl+Shift+U Make uppercase.
Ctrl+U Make lowercase.
Ctrl+Shift+S Convert tabs to spaces.
Ctrl+Shift+T Convert spaces to tabs.
Ctrl+Shift+A Convert to ANSI.
Ctrl+Shift+O Convert to OEM.
Insert
Ctrl+F5 Time/date (short form).
Ctrl+Shift+F5 Time/date (long form).
Ctrl+F9 Filename.
Ctrl+Shift+F9 Path and filename.
Find, replace
Ctrl+F Find.
F3 Find next.
Shift+F3 Find previous.
Ctrl+H Replace.
Ctrl+J Jump to line.
Ctrl+G Jump to line.
Bookmarks
F2 Goto next bookmark.
Shift+F2 Goto previous bookmark.
Ctrl+F2 Toggle bookmark.
Ctrl+Shift+F2 Clear all bookmarks.
Syntax scheme
F12 Select syntax scheme.
Shift+F12 Select 2nd default syntax scheme.
Ctrl+F12 Customize syntax schemes.
F11 Select default text syntax scheme.
Ctrl+F11 Select web source code syntax scheme.
Shift+F11 Select XML document syntax scheme.
View
Ctrl+W Toggle word wrap.
Ctrl+Shift+L Show long line marker.
Ctrl+Shift+G Show indentation guides.
Ctrl+Shift+N Show line numbers.
Ctrl+Shift+M Show selection margin.
Ctrl+Shift+8 Show whitespace.
Ctrl+Shift+9 Show line endings.
Ctrl+Shift+0 Show wrap symbols.
Ctrl+Shift+V Toggle visual brace matching.
Ctrl+Shift+H Toggle auto close HTML/XML.
Zoom
Ctrl++ Zoom in.
Ctrl+- Zoom out.
Ctrl+/ Reset zoom.
Settings
Alt+T Always on top.
Alt+U Transparent mode.
F7 Save settings now.
Misc.
Ctrl+Q Exit Notepad2.
Esc Optionally minimize or exit Notepad2.
F1 Display version info.
Tips and Tricks, Special Features, Limitations
Regular Expression Syntax
. Matches any character
\( This marks the start of a region for tagging a match.
\) This marks the end of a tagged region.
\n Where n is 1 through 9 refers to the first through ninth
tagged region when replacing. For example, if the search
string was Fred\([1-9]\)XXX and the replace string was
Sam\1YYY, when applied to Fred2XXX this would generate
Sam2YYY.
\< This matches the start of a word.
\> This matches the end of a word.
\x This allows you to use a character x that would otherwise
have a special meaning. For example, \[ would be interpreted
as [ and not as the start of a character set.
[...] This indicates a set of characters, for example, [abc] means
any of the characters a, b or c. You can also use ranges, for
example [a-z] for any lower case character.
[^...] The complement of the characters in the set. For example,
[^A-Za-z] means any character except an alphabetic character.
^ This matches the start of a line (unless used inside a set,
see above).
$ This matches the end of a line.
* This matches 0 or more times. For example, Sa*m matches Sm,
Sam, Saam, Saaam and so on.
+ This matches 1 or more times. For example, Sa+m matches Sam,
Saam, Saaam and so on.
-----> Examples (don't use quotes)
- Quote lines: find "^" replace with "> "
- Unquote lines: find "^> " replace with ""
- Remove line numbers: find "^[0-9]+" replace with ""
- Convert tabs to double spaces: find "\t" replace with " "
Setting more Options
The Notepad2.reg file contains additional program settings that must
be modified directly in the registry. These settings include options
to customize the toolbar bitmaps and texts. Inspect Notepad2.reg to
find more explanations.
Command Line Parameters
Notepad2.exe [/g ln[,col]] [/n] [/c] [/p x,y,cx,cy[,max]]
[/i] [/u] [/?] [file]
file: File to open, can be a relative pathname, or a shell link.
This must be the last argument, quotes are not necessary.
/g: Jump to specified position, a line of -1 means end of file.
/n: Always open a new Notepad2 window, even if the "reuse-window"
option is on.
/c: Open a new Notepad2 window and paste the clipboard contents.
/b: Open a new Notepad2 paste board to collect clipboard entries.
/p: Set window position to x,y with size cx,cy, optional value
max set to nonzero to maximize window.
/i: Start as tray icon.
/u: Remove the registry entries created by Notepad2.
/?: Display a brief summary about command line parameters.
Import and Export Settings
The Notepad2 settings can be exported from the registry and imported
again on a different computer or for a different user. Run
reg.exe export HKCU\Software\Notepad2 MySettings.reg
to export the settings to MySettings.reg. Now either launch this file
from Explorer or use
reg.exe import MySettings.reg
to restore the settings. Just the style settings can be grabbed with
reg.exe export HKCU\Software\Notepad2\Styles MyStyles.reg
On some earlier versions of Windows, the reg.exe command line tool is
probably not available, then you have to switch to regedit.exe.
Source Code
Notepad2 is based on the Scintilla source code editing component:
http://www.scintilla.org
The full Notepad2 source code is distributed under the terms of the
GNU General Public License and can be found at:
http://www.flos-freeware.ch |
|
| Back to top |
|
 |
WhiteCloud
Joined: 19 Jun 2004 Posts: 68
|
Posted: Sun Jul 04, 2004 12:15 am Post subject: |
|
|
Thanks for the help, fellas
it's not necessary to put a binary input feature in
i can just manually replace the linefeeds in a text editor before i run my ahk script every couple weeks
it was mostly out of curiosity that i posted this thread _________________ AHK = Hella fun |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Sun Jul 04, 2004 1:58 am Post subject: |
|
|
| Quote: | | i can just manually replace the linefeeds in a text editor before i run my ahk script every couple weeks |
Are you sure that's necessary? AHK should read Unix files and Windows files in the same way. Additionally, it can write in the Unix format by preceding the output filename with an asterisk.
Does your text file vary from line to line as to whether there is a `r`n vs. just a plain `n? |
|
| Back to top |
|
 |
WhiteCloud
Joined: 19 Jun 2004 Posts: 68
|
Posted: Sun Jul 04, 2004 6:11 am Post subject: |
|
|
| Chris wrote: | | Does your text file vary from line to line as to whether there is a `r`n vs. just a plain `n? |
That's what I thought was happening. It turns out I was mistaken. The files I'm reading are query results from a database. The \n was actually a \r\n enclosed in double quotes (with some other text) so when i dragged the file into excel it got seen as a \n. (a new line inside a cell)
on a side note, I fixed my initial problem by getting rid of only the \r\n characters inside of double quotes with this ahk script:
| Code: | setbatchlines -1
append_without_newline = 0
loop read, nonparsable.txt
{
loop parse, A_loopreadline
{
if A_LoopField = "
{
if append_without_newline = 0
{
append_without_newline = 1
}
else
{
append_without_newline = 0
}
}
}
if append_without_newline = 1
{
fileappend %this_line%, parsable.txt
}
else
{
fileappend %this_line%`n, parsable.txt
}
}
setbatchlines 10ms |
now i have a nice clean file with 1 record per line. AHK saved the day once again.
/me tips his hat _________________ AHK = Hella fun |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|