TabPack()

TabPack()

Pack fill characters to appropriate tab characters

Syntax

     TabPack( <cString>, [<nTabWidth>], [<cFillChar|nFillChar>],
             [<cNewLineCharacters>], [<cTabChar|nTabChar>],
             [<lIgnore141>] ) -> cPackedString

Arguments

<cString> String to alter <nTabWidth>

<cFillChar|nFillChar> Width of tab or character to use to fill <cNewLineCharacters> string indicating new line, default is the string returned by hb_eol()

<cTabChar|nTabChar> character indicating a tab stop, default is chr(9)

<lIgnore141> .T., if the soft-CR used by MEMOEDIT() should be ignored as a newline indicator, default is .F. (functions uses chr(141))

Returns

TABPACK() returns the modified character string.

Description

This function does not simply exchange a simple sequence of the same characters for a tab; instead, it takes into account the true tab positions. If a space (or the <cCharacter|nCharacter>) is found at a tab position, and immediately preceding it there is at least one identical character, the function replaces this sequence (maximum <nTabWidth>) with a CHR(9). With tab characters, text can be packed by individual tab widths. As with every good text editor, there is no replacement with a tab within single or double leading characters.

Notes

. For the beginning of a line, the function takes into account the “normal” carriage return (CHR(13)/CHR(10)) as well as the high bit return (CHR(141)) used by MEMOEDIT(). Previously existing tab characters are also taken into account. . If another tab already exists, this tab can be removed with TABEXPAND(). The new tab can then be inserted using TABPACK().

Example

       We have avoided replacing spaces with tabs in the following examples to
       keep the example legible.  Tab width is 8 (default).  "*" is exchanged
       for tab characters.
       ? TABPACK("AAAAAAA*", "*")           // "AAAAAAA*"
       ? TABPACK("AAAAA***", "*")           // "AAAAA" + CHR(9)
       ? TABPACK("AAAAA*****", "*")         // "AAAAA" + CHR(9) + "**"
       crlf   :=  CHR(13) + CHR(10)
       cText  :=  "ABCD+" + crlf + "++---+++++"
       ? TABPACK(cText, 4, "+")             // "ABCD+" + crlf +
                                            // "++---" + CHR(9) + "++"

Compliance

TabPack() is compatible with CT3’s TabPack(), but extended by Harbour; there are three new parameters for a better fine control of the function’s behaviour.

Platforms

All

Files

Source is tab.c, library is libct.

Seealso

TabExpand()

Harbour All Functions – T

TabExpand
TabPack

Tan

TanH

TBrowseDB

TBrowseNew

TFileRead

THtml

Time

TimeValid

TNortonGuide 

Token
TokenAt
TokenEnd
TokenExit
TokenInit
TokenLower
TokenNext
TokenNum
TokenSep
TokenUpper

Tone

TOs2

Transform
Trim

TRtf

TTroff

 Type

String Functions

AddASCII

AfterAtNum

AllTrim
Asc

ASCIISum

ASCPos
At

AtAdjust

AtNum
AtRepl
AtToken

BeforAtNum

Chr

CharAdd
CharAnd
CharEven
CharHist
CharList
CharMirr
CharMix
CharNoList
CharNot
CharOdd
CharOne
CharOnly
CharOr
CharPix
CharRela
CharRelRep
CharRem
CharRepl
CharRLL
CharRLR
CharSHL
CharSHR
CharSList
CharSort
CharSub
CharSwap
CharWin
CharXOR

CountLeft
CountRight
Descend
Empty
hb_At
hb_RAt
hb_ValToStr
IsAlpha
IsDigit
IsLower
IsUpper

JustLeft
JustRight

Left
Len
Lower
LTrim

NumAt
NumToken
PadLeft
PadRight

PadC
PadL
PadR

POSALPHA
POSCHAR
POSDEL
POSDIFF
POSEQUAL
POSINS
POSLOWER
POSRANGE
POSREPL
POSUPPER

RangeRem
RangeRepl

RAt

RemAll

RemLeft
RemRight
ReplAll

Replicate

ReplLeft

ReplRight

RestToken

Right
RTrim

SaveToken

SetAtLike
Space
Str

StrDiff

StrFormat

StrSwap

StrTran
StrZero
SubStr

TabExpand
TabPack

Token

TokenAt
TokenEnd
TokenExit
TokenInit
TokenLower
TokenNext
TokenNum
TokenSep
TokenUpper

Transform
Trim
Upper
Val

ValPos
WordOne
WordOnly
WordRem
WordRepl
WordSwap

WordToChar


CT_TABEXPAND

 TABEXPAND()
 Converts tabs to spaces
------------------------------------------------------------------------------
 Syntax

     TABEXPAND(<cString>,[<nTabWidth>],
        [<cCharacter|nCharacter>]) --> cString

 Arguments

     <cString>  Designates the string that is processed.

     <nTabWidth>  Designates the tab width.  The default value is 8.

     <cCharacter|nCharacter>  Designates the characters that are used
     when expanding the tabs.  The default value is a space, CHR(32).

 Returns

     The modified <cString> is returned.

 Description

     The TABEXPAND() function replaces all tab characters (CHR(9)) in
     <cString> with the corresponding number of spaces or <cCharacter|
     nCharacter>.  The <nTabWidth> parameter can be used to set varying tab
     widths.

 Notes

     .  In the absence of the <nTabWidth> parameter, TABEXPAND() has a
        default tab width of 8.

     .  The carriage return and line feed, where the high bit is set,
        are taken into consideration.

     .  SETTABS() does not affect this function.

 Examples

     .  TABEXPAND() only fills to the next tab position:

        ? TABEXPAND("-" +CHR(9) +"!")                  // "-       !"
        ? TABEXPAND("----" +CHR(9) +"!")               // "----    !"

     .  You can fill with any character you like:

        ? TABEXPAND("-" +CHR(9) +"!", "+")             // "-+++++++!"

     .  The tab width can be selected:

        ? TABEXPAND("-" +CHR(9) +"!", 4)               // "-   !"
        ? TABEXPAND("----" +CHR(9) +"!", 8)            // "----    !"
        ? TABEXPAND("----" +CHR(9) +"!", 8, "+")       // "----++++!"

See Also: TABPACK()

 

Tools – String Manipulations

Introduction 
ADDASCII()   Adds a value to each ASCII code in a string
AFTERATNUM() Returns remainder of a string after nth appearance of sequence
ASCIISUM()   Finds sum of the ASCII values of all the characters of a string
ASCPOS()     Determines ASCII value of a character at a position in a string
ATADJUST()   Adjusts the beginning position of a sequence within a string
ATNUM()      Determines the starting position of a sequence within a string
ATREPL()     Searches for a sequence within a string and replaces it
ATTOKEN()    Finds the position of a token within a string
BEFORATNUM() Returns string segment before the nth occurrence of a sequence
CENTER()     Centers a string using pad characters
CHARADD()    Adds the corresponding ASCII codes of two strings
CHARAND()    Links corresponding ASCII codes of paired strings with AND
CHAREVEN()   Returns characters in the even positions of a string
CHARLIST()   Lists each character in a string
CHARMIRR()   Mirrors characters within a string
CHARMIX()    Mixes two strings together
CHARNOLIST() Lists the characters that do not appear in a string
CHARNOT()    Complements each character in a string
CHARODD()    Returns characters in the odd positions of a string
CHARONE()    Reduces adjoining duplicate characters in string to 1 character
CHARONLY()   Determines the common denominator between two strings
CHAROR()     Joins the corresponding ASCII code of paired strings with OR
CHARPACK()   Compresses (packs) a string
CHARRELA()   Correlates the character positions in paired strings
CHARRELREP() Replaces characters in a string depending on their correlation
CHARREM()    Removes particular characters from a string
CHARREPL()   Replaces certain characters with others
CHARSORT()   Sorts sequences within a string
CHARSPREAD() Expands a string at the tokens
CHARSWAP()   Exchanges all adjoining characters in a string
CHARUNPACK() Decompresses (unpacks) a string
CHARXOR()    Joins ASCII codes of paired strings with exclusive OR operation
CHECKSUM()   Calculates the checksum for a character string (algorithm)
COUNTLEFT()  Counts a particular character at the beginning of a string
COUNTRIGHT() Counts a particular character at the end of a string
CRYPT()      Encrypts and decrypts a string
CSETATMUPA() Determines setting of the multi-pass mode for ATXXX() functions
CSETREF()    Determines whether reference sensitive functions return a value
EXPAND()     Expands a string by inserting characters
JUSTLEFT()   Moves characters from the beginning to the end of a string
JUSTRIGHT()  Moves characters from the end of a string to the beginning
LIKE()       Compares character strings using wildcard characters
LTOC()       Converts a logical value into a character
MAXLINE()    Finds the longest line within a string
NUMAT()      Counts the number of occurrences of a sequence within a string
NUMLINE()    Determines the number of lines required for string output
NUMTOKEN()   Determines the number of tokens in a string
PADLEFT()    Pads a string on the left to a particular length
PADRIGHT()   Pads a string on the right to a particular length
POSALPHA()   Determines position of first alphabetic character in a string
POSCHAR()    Replaces individual character at particular position in string
POSDEL()     Deletes characters at a particular position in a string
POSDIFF()    Finds the first position from which two strings differ
POSEQUAL()   Finds the first position at which two strings are the same
POSINS()     Inserts characters at a particular position within a string
POSLOWER()   Finds the position of the first lower case alphabetic character
POSRANGE()   Determines position of first character in an ASCII code range
POSREPL()    Replaces one or more characters from a certain position
POSUPPER()   Finds the position of the first uppercase, alphabetic character
RANGEREM()   Deletes characters that are within a specified ASCII code range
RANGEREPL()  Replaces characters within a specified ASCII code range
REMALL()     Removes characters from the beginning and end of a string
REMLEFT()    Removes particular characters from the beginning of a string
REMRIGHT()   Removes particular characters at the end of a string
REPLALL()    Exchanges characters at the beginning and end of a string
REPLLEFT()   Exchanges particular characters at the beginning of a string
REPLRIGHT()  Exchanges particular characters at the end of a string
RESTTOKEN()  Recreates an incremental tokenizer environment
SAVETOKEN()  Saves the incremental tokenizer environment to a variable
SETATLIKE()  Provides an additional search mode for all AT functions
STRDIFF()    Finds similarity between two strings (Levenshtein Distance)
STRSWAP()    Interchanges two strings
TABEXPAND()  Converts tabs to spaces
TABPACK()    Converts spaces in tabs
TOKEN()      Selects the nth token from a string
TOKENAT()    Determines the most recent TOKENNEXT() position within a string
TOKENEND()   Determines if more tokens are available in TOKENNEXT()
TOKENINIT()  Initializes a string for TOKENNEXT()
TOKENLOWER() Converts initial alphabetic character of a token into lowercase
TOKENNEXT()  Provides an incremental tokenizer
TOKENSEP()   Provides separator before/after most recently retrieved TOKEN()
TOKENUPPER() Converts the initial letter of a token into upper case
VALPOS()     Determines numerical value of character at particular position
WORDONE()    Reduces multiple appearances of double characters to one
WORDONLY()   Finds common denominator of 2 strings on double character basis
WORDREPL()   Replaces particular double characters with others
WORDSWAP()   Exchanges double characters lying beside each other in a string
WORDTOCHAR() Exchanges double characters for individual ones