xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

CharSort()

Sorts character (sequences) within a string.

Syntax

CharSort( <cString>     , ;
         [<nSeqLen>]    , ;
         [<nCompareLen>], ;
         [<nSkipChars>] , ;
         [<nSkipSeq>]   , ;
         [<nSortLen>]   , ;
         [<lDescending>]  ) --> cResult

Arguments

<cString>
This is the character string to process.
<nSeqLen>
This is a numeric value defining the number of characters per character sequence to be sorted. The default value is 1 (single character).
<nCompare>
This is a numeric value defining the number of characters per character sequence that are recognized in a sort. The default is <nSeqLen>, so that all characters of a sequence are recognized.
<nSkipChars>
This numeric parameter defaults to 0 so that the function begins sorting with the first character of <cString>. Passing a value > 0 instructs the function to ignore the first <nSkipChars> characters in the operation.
<nSkipSeq>
This numeric parameter defaults to 0 so that the functions sorts character sqeuences with the first character of a sequence. Passing a value > 0 instructs the function to ignore the first <nSkipSeq> characters in a character sequence.
<nSortLen>
This numeric parameter defaults to Len( <STring> so that the functions sorts all character sqeuences contained in <cString>. Passing a value > 0 instructs the function to stop sorting at position <nSkipChars> + <nSortLen>.
<lDescending>
By default, the function sorts in asscending order. When .T. (true) is passed for <lDescending>, the result string is sorted in descending order.

Return

The function returns the sorted string or a null string ("") when an error occurs.

Info

See also:CharRela()
Category: CT:String manipulation , Character functions
Source:ct\charsort.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example demonstrates various sort results of CharSort()

   PROCEDURE Main
      LOCAL cStr := "4ef2ab1cd3gh"

      // sort single characters
      ? CharSort( cStr )             // result: 1234abcdefgh

      // sort character pairs
      ? CharSort( cStr, 2 )          // result: 1c4eabd3f2gh

      // sort character triplets (by digit)
      ? CharSort( cStr, 3 )          // result: 1cd2ab3gh4ef

      // sort character triplets (by alphabet)
      ? CharSort( cStr, 3, 2, 0, 1 ) // result: 2ab1cd4ef3gh
   RETURN

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe