November 28, 2020, 02:08:34 PM

Author Topic: [bmx] 2 Split String to Array funcs by klepto2 [ 1+ years ago ]  (Read 608 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : 2 Split String to Array funcs
Author : klepto2
Posted : 1+ years ago

Description : In my module I have got 2 methods for splitting Strings and send them to an Array. I have made 2 functions out of them to share them with you.

The first one called Return_strip devides the string as often it finds the delivered ASCII code in the String.

The second one called Return_strip2 devides the string as long as the delivered _strip:string is. i.e: the stripstring is
" :" the main string will be divided two times.
("Load Map:Test.dat" will result in 1. "load" and 2. "Map:Test.dat" with the first function but with the second one you will get : 1."Load" 2."Map" 3."Test.Dat")


Code :
Code: BlitzMax
  1. Strict
  2.  
  3. Local I:Int
  4.  
  5.  
  6.  
  7. Print "Return_strip2 : ('Load Map:Test.dat')"
  8.  
  9. Local Strip:String[]
  10. Strip = Return_Strip2("Load Map:Test.dat"," :")
  11. For I = 0 To Strip.length-1
  12. Print I + " : " + Strip[I]
  13. Next
  14.  
  15. Print "Return_strip  : ('Load Map:Test.dat')"
  16.  
  17. Local Strip2:String[]
  18. Strip2 = Return_Strip("Load Map:Test.dat",32)
  19. For I = 0 To Strip2.length-1
  20. Print I + " : " + Strip2[I]
  21. Next
  22.  
  23.  
  24.  
  25.  
  26. Function Return_Strip2:String[](_String:String,_strip:String)
  27.  
  28.         Local Text_Array : String[1]
  29.         Local R_Text:String = _string
  30.         Local i:Int = 0
  31.  
  32.         Repeat
  33.                 If R_Text.Length = 0 Then Exit
  34.                         Local sp_p:Int = R_Text.Find(Mid(_strip,I+1,1))
  35.                         If sp_p = - 1 Or I > _strip.length -1 Then
  36.                                 Text_Array[I] = R_Text
  37.                                 Exit
  38.                         End If
  39.                         Text_Array[I] = Left(R_Text,sp_p)
  40.                         R_Text = Right(R_Text,(R_text.Length - sp_p)-1)
  41.                         I:+1
  42.                         Text_Array = Text_array[..I+1]
  43.         Forever
  44.        
  45.         Return Text_array      
  46.        
  47. End Function
  48.  
  49. Function Return_Strip:String[](_String:String,_strip:Int)
  50.  
  51.         Local Text_Array : String[1]
  52.         Local R_Text:String = _string
  53.         Local i:Int = 0
  54.  
  55.         Repeat
  56.                 If R_Text.Length = 0 Then Exit
  57.                         Local sp_p:Int = R_Text.Find(Chr(_strip))
  58.                         If sp_p = - 1  Then
  59.                                 Text_Array[I] = R_Text
  60.                                 Exit
  61.                         End If
  62.                         Text_Array[I] = Left(R_Text,sp_p)
  63.                         R_Text = Right(R_Text,(R_text.Length - sp_p)-1)
  64.                         I:+1
  65.                         Text_Array = Text_array[..I+1]
  66.         Forever
  67.        
  68.         Return Text_array      
  69.        
  70. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal