Array-Funktion: Explode()
Übersicht

![]() |
ArtemisBetreff: Array-Funktion: Explode() |
![]() Antworten mit Zitat ![]() |
---|---|---|
Array-Funktionen
Hier werde ich nützliche Array-Funktionen auflisten. Bisherige Funktionen:
Explode:String[](Text:String, Separator:String, MaxLength:Int) Version 1.1 Code: [AUSKLAPPEN] Function Explode:String[](Text:String, Separator:String, MaxLength:Int=0)
If Separator = "" Then Return Null If Text = "" Then Return Null Local SeparatorCount:Int = 0 Local TextPosition :Int = 1 Local LoopCounter :Int Local Occurrence :Int While Instr(Text, Separator, TextPosition) TextPosition = Instr(Text, Separator, TextPosition) + 1 SeparatorCount :+ 1 Wend If (MaxLength = 0) Or (MaxLength >= SeparatorCount) Then MaxLength = SeparatorCount EndIf Local Array:String[] = New String[MaxLength+1] If MaxLength <> SeparatorCount Then MaxLength :- 1 EndIf For LoopCounter = 0 To MaxLength Occurrence = Instr(Text, Separator) If Occurrence > 0 Then Array[LoopCounter] = Left(Text, Occurrence-1) Text = Mid(Text, Occurrence+Separator.Length) Else Array[LoopCounter] = Text Text = "" EndIf Next If Text <> "" Then Array[LoopCounter] = Text EndIf Return Array EndFunction |
||
- Zuletzt bearbeitet von Artemis am So, Apr 30, 2006 18:38, insgesamt 4-mal bearbeitet
Dreamora |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Die Funktion heisst häufig auch Split.
Liese sich optimieren, indem du den Separated Array nur um *2 vergrösserst wenn er die aktuelle grösse überschreitet und dann am schluss auf die tatsächliche grösse reduzierst. Aktuell baut es relativ viel datenmüll auf weil jeder Slice den alten Array zu Garbage macht, sprich tunlichst vermieden werden sollten. |
||
Ihr findet die aktuellen Projekte unter Gayasoft und könnt mich unter @gayasoft auf Twitter erreichen. |
![]() |
Artemis |
![]() Antworten mit Zitat ![]() |
---|---|---|
Jo, werde das so machen, dass ich am Anfang gucke, in wie viele Teile das Aufgespaltet werden soll, und dann erst den String splitte. | ||
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group