Ooops
November 25, 2020, 04:47:39 AM

Author Topic: [bb] Alphabetical sort by bytecode77 [ 1+ years ago ]  (Read 647 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Alphabetical sort by bytecode77 [ 1+ years ago ]
« on: June 29, 2017, 12:28:43 AM »
Title : Alphabetical sort
Author : bytecode77
Posted : 1+ years ago

Description : This function checks two strings and tells which one is higher in alphabet.

It is purposely not case sensitive. To add case sensitivity, remove these two lines from the code:
Code: [Select]
If ch1 => 65 And ch1 <= 90 Then ch1 = Asc(Lower(Chr(ch1)))
If ch2 => 65 And ch2 <= 90 Then ch2 = Asc(Lower(Chr(ch2)))


Code :
Code: BlitzBasic
  1. ;Return values of this function:
  2. ;    -1  => both strings are identical
  3. ;     1  => s1$ is higher in alphabet
  4. ;     0  => s2$ is higher in alphabet
  5.  
  6. ;This function is NOT case sensitive.
  7.  
  8. Function SortStrings(s1$, s2$)
  9. If Len(s1$) > Len(s2$) Then
  10.         While Len(s1$) > Len(s2$)
  11.                 s2$ = s2$ + Chr(1)
  12.         Wend
  13. ElseIf Len(s2$) > Len(s1$) Then
  14.         While Len(s2$) > Len(s1$)
  15.                 s1$ = s1$ + Chr(1)
  16.         Wend
  17. EndIf
  18. ln = Len(s1$)
  19. For i = 1 To ln
  20.         ch1 = Asc(Mid(s1$, i, 1))
  21.         If ch1 => 65 And ch1 <= 90 Then ch1 = Asc(Lower(Chr(ch1)))
  22.         ch2 = Asc(Mid(s2$, i, 1))
  23.         If ch2 => 65 And ch2 <= 90 Then ch2 = Asc(Lower(Chr(ch2)))
  24.        
  25.         If ch1 < ch2 Then
  26.                 Return True
  27.         ElseIf ch1 > ch2 Then
  28.                 Return False
  29.         EndIf
  30. Next
  31. Return -1
  32. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal