HB_EOL()

HB_EOL()

Returns the newline character(s) to use with the current OS

Syntax

      hb_eol() --> cString

Returns

<cString> A character string containing the character or characters required to move the screen cursor or print head to the start of a new line.

Description

Returns a character string containing the character or characters required to move the screen cursor or print head to the start of a new line for the operating system that the program is running on (or thinks it is running on, if an OS emulator is being used).

Under HB_OS_UNIX operating system the return value is the Line-Feed character (0x0a, CHR(10)); with other operating systems (like DOS) the return value is the Carriage-Return plus Line-Feed characters (0x0d 0x0a, CHR(13)+CHR(10)).

Examples

      // Get the newline character(s) for the current OS.
      // Get the newline character(s) for the current OS.
      STATIC s_cNewLine
      ...
      s_cNewLine := hb_eol()
      ...
      OutStd( "Hello World!" + s_cNewLine )

Tests

      ? ValType( hb_eol() ) == "C"
      ? Len( hb_eol() ) == 1

Compliance

Harbour

Platforms

All

Files

Library is rtl

Seealso

OS(), OUTSTD(), OUTERR()

SP_SFREADLINE

()

  Short:
  ------
  SFREADLINE() Reads in text up to the next CRLF in a text file

  Returns:
  --------
  <cLine> => line read in

  Syntax:
  -------
  SFREADLINE(nHandle)

  Description:
  ------------
  Reads in text up to the next CRLF in a text file. The
  pointer is moved back to the starting position when done. To move to a
  new line, use  FMOVE2PRIOR() or FMOVE2NEXT().

  Examples:
  ---------
   nHandle := fopen("Report.doc")

   ?sfreadline(handle)
   while fmove2next(handle)
     ?sfreadline(handle)
   end

  Source:
  -------
  S_FREADL.PRG

 

SP_FMOVE2PRIOR

FMOVE2PRIOR()

  Short:
  ------
  FMOVE2PRIOR() Moves to beginning of previous CRLF delimited
  line in a text file

  Returns:
  --------
  <lSuccess> => for success

  Syntax:
  -------
  FMOVE2PRIOR(nHandle)

  Description:
  ------------
  Moves pointer in a text file <nHandle> opened with
  FREAD() to the beginning if the next CRLF delimited line in the
  file. Returns .f. if unable to.

  Examples:
  ---------
   FMOVE2PRIOR(handle)

   ?FREADLINE(handle)

  Source:
  -------
  S_FM2P.PRG

 

SP_FMOVE2NEXT

FMOVE2NEXT()

  Short:
  ------
  FMOVE2NEXT() Move to beginning of next line in a text file

  Returns:
  --------
  <lSuccess> => success in doing so

  Syntax:
  -------
  FMOVE2NEXT(nHandle)

  Description:
  ------------
  Moves pointer in text file <nHandle> to beginning of
  next line.

  Presuming lines end in CRLF. Returns <expL> for
  success. End of file would return .f.

  Examples:
  ---------

   // this will list off the text file REPORT.LST to the  screen

   h := fopen("report.lst")
   ?SFREADLINE(h)
   while  FMOVE2NEXT(h)
    ?SFREADLINE(h)
   end

  Source:
  -------
  S_FM2N.PRG

 

Parsing Text – Tokens

/*
From Harbour changelog (at 2007-04-04 10:35 UTC+0200 By Przemyslaw Czerpak )
Added set of functions to manipulate string tokens:
HB_TOKENCOUNT( <cString>, [ <cDelim> ], [ <lSkipStrings> ],
 [ <lDoubleQuoteOnly> ] ) -> <nTokens>

 HB_TOKENGET( <cString>, <nToken>, [ <cDelim> ], [ <lSkipStrings> ],
 [ <lDoubleQuoteOnly> ] ) -> <cToken>

 HB_TOKENPTR( <cString>, @<nSkip>, [ <cDelim> ], [ <lSkipStrings> ],
 [ <lDoubleQuoteOnly> ] ) -> <cToken>

 HB_ATOKENS( <cString>, [ <cDelim> ], [ <lSkipStrings> ],
 [ <lDoubleQuoteOnly> ] ) -> <aTokens>

 All these functions use the same method of tokenization. They can
 accept as delimiters string longer then one character. By default
 they are using " " as delimiter. " " delimiter has special mening

 Unlike other delimiters repeted ' ' characters does not create empty
 tokens, f.e.: 

 HB_ATOKENS( " 1 2 3 " ) returns array:
 { "1", "2", "3" }

 Any other delimiters are restrictly counted, f.e.:

 HB_ATOKENS( ",,1,,2,") returns array:
 { "", "", "1", "", "2", "" }
And a strong suggession made at 2009-12-09 21:25 UTC+0100 ( By Przemyslaw Czerpak )
I strongly suggest to use hb_aTokens() and hb_token*() functions.
 They have more options and for really large data many times
 (even hundreds times) faster.

*/
#define CRLF HB_OsNewLine()
PROCEDURE Main()
LOCAL cTextFName := "Shakespeare.txt",;
 c1Line 

 SET COLO TO "W/B"
 SetMode( 40, 120 )

 CLS

 HB_MEMOWRIT( cTextFName,;
 "When in eternal lines to time thou grow'st," + CRLF + ;
 "So long as men can breathe, or eyes can see," + CRLF + ;
 "So long lives this, and this gives life to thee." )

 aLines := HB_ATOKENS( MEMOREAD( cTextFName ), CRLF )

 ?
 ? "Text file line by line :"
 ?
 AEVAL( aLines, { | c1Line | QOUT( c1Line ) } )
 ?
 WAIT "Press a key for parsing as words"
 CLS
 ?
 ? "Text file word by word :"
 ?
 FOR EACH c1Line IN aLines
 a1Line := HB_ATOKENS( c1Line ) 
 AEVAL( a1Line, { | c1Word | QOUT( c1Word ) } )
 NEXT 
 ?
 WAIT "Press a key for parsing directly as words"
 CLS
 ?
 ? "Text file directly word by word :"
 ?
 aWords := HB_ATOKENS( MEMOREAD( cTextFName ) )
 AEVAL( aWords, { | c1Word | QOUT( c1Word ) } ) 

 ?
 @ MAXROW(), 0
 WAIT "EOF TP_Token.prg" 

RETURN // TP_Token.Main()
 TP_Token

Parsing Text – FParse()

/*
FParse()
Parses a delimited text file and loads it into an array.
Syntax :
FParse( <cFileName>, <cDelimiter> ) --> aTextArray
Arguments :
<cFileName> : This is a character string holding the name of the text file to load 
 into an array. It must include path and file extension. 
 If the path is omitted from <cFileName>, 
 the file is searched in the current directory. 

 <cDelimiter> : This is a single character used to parse a single line of text. 
 It defaults to the comma.
Return :
The function returns a two dimensional array, or an empty array when the file 
cannot be opened. 

Description :

 Function FParse() reads a delimited text file and parses each line 
 of the file at <cDelimiter>. The result of line parsing is stored in an array.
This array, again, is collected in the returned array, 
 making it a two dimensional array
FParse() is mainly designed to read the comma-separated values (or CSV) file format, 
 were fields are separated with commas and records with new-line character(s). 

Library is : xHb 

*/
#define CRLF HB_OsNewLine()
PROCEDURE Main()
LOCAL cTextFName := "Shakespeare.txt",;
      a1Line 

 SET COLO TO "W/B"
 SetMode( 40, 120 )

 CLS

 HB_MEMOWRIT( cTextFName,;
              "When in eternal lines to time thou grow'st," + CRLF + ;
              "So long as men can breathe, or eyes can see," + CRLF + ;
              "So long lives this, and this gives life to thee." )

 aLines := FParse( cTextFName, " " )

 ?
 ? "Text file word by word :"
 ?
 FOR EACH a1Line IN aLines
    AEVAL( a1Line, { | c1Word | QOUT( c1Word ) } )
 NEXT 
 ?
 @ MAXROW(), 0
 WAIT "EOF TP_FParse.prg" 

RETURN // TP_FParse.Main()

TP_FParse

Hex View

Hexadecimal file viewer.

This is a experimental project with first intend of point out the power of Harbour and HMG. So, HexView is considerably slow on large files, please be patient.

Download here ( source only ).