Re: sort string beginning at index?



Stan McCann wrote:
>
> I need some recommendations as to how to go about sorting a string not
> from the beginning of the string, but from a given index into the
> string. I am reading a data file into an array using file(), then
> looping through the string which contains fields seperated by |. Do I
> have to explode each individual record to sort them using
> array_multisort()? What I was hoping for was something like sort
> ($array, SORT_STRING, 15) where 15 is the index into the string to sort
> on instead of starting at 0.

// Untested
function sort_starting_at_index($array, $index) {
$temp = array();
$newarray = array();
foreach ($array as $key=>$value) {
$temp[$key] = substr($value, $index);
}
asort($temp, SORT_STRING);
foreach ($temp as $key=>$value) {
$newarray[] = $array[$key];
}
return $newarray;
}

Cheers,
NC

.



Relevant Pages

  • sort 1-D array of doubles for Olaf Schmidt
    ... A few weeks Olaf Schmidt posted a VB6 routine to sort a 1-D array of strings very fast indeed. ... fastest way to change case of string. ... Dim i As Long, j As Long, Lo As Long, Hi As Long, StPtr As Long ...
    (microsoft.public.vb.general.discussion)
  • Re: Collection Structure
    ... property StringID you want ... where inarr is the String array and outarr is an array of longs containing ... needs to sort the input array keeping track of the original position (I use ...
    (microsoft.public.vb.com)
  • Help in French|Spanish|German translation.
    ... I am also an author of User-defined string functions. ... WORDTRANEX (cSearched, cArExpressionSought | cExpressionSough, ... each string of the array is searched ... If the parameter nArStartOccurrence is -1 or omitted, the replacement starts ...
    (microsoft.public.fox.helpwanted)
  • Re: About word frequency
    ... Use the split function to turn the string into an array. ... Sort the array. ... For each sLine in aList ...
    (microsoft.public.scripting.vbscript)
  • Re: passing a string to a dll
    ... Joe, I really appreciate you taking the time to demonstrate this. ... sure how I would implement indexing it for random alphanumeric codes. ... I might handle the array. ... I actually have been wondering if I could use a second string ...
    (microsoft.public.vc.mfc)