StringStream
Übersicht

![]() |
DAKBetreff: StringStream |
![]() Antworten mit Zitat ![]() |
---|---|---|
Mein kleines StringStream-Modul.
Das Ganze hat den Sinn, dass man quasi ein Array beliebiger Länge in ein String speichern kann. Dieses kann dann per Stream-ähnlichen Befehlen ausgelesen werden. Code: [AUSKLAPPEN] Rem
bbdoc: Streams/StringStream End Rem Module DAK.StringStream Import BRL.Retro ModuleInfo "Version: 1.00" ModuleInfo "Author: DAK" Rem bbdoc: Streamobject used for Stringstreams about: End Rem Type TStringStream Field sStr:String, iPos:Int, sep:String Rem bbdoc: Returns 1 if the stringstream comes to an end. about: End Rem Method Eof:Byte() If iPos=0 Then Return 1 End Method Rem bbdoc: Reads the next line of the stringstream. about: End Rem Method ReadLine:String() If iPos=0 Then Return "" Local iPos2:Int = Instr(sStr, sep, iPos+1) Local out:String If iPos2>0 Then out = Mid(sStr, iPos+Len(sep), iPos2-iPos-Len(sep)) iPos = iPos2 Return Replace(out, sep, "") End Method Rem bbdoc: Writes a line after the last read line. about: End Rem Method WriteLine(ln:String) Local out:String=Left(sStr,ipos-1)+sep+ln+Mid(sStr,ipos) sStr = out End Method Rem bbdoc: Sets the position of the cursor in the StringStream. about: Returns 0 if there are less lines then nr. End Rem Method SetPos:Byte(nr:Int) iPos=0 For Local i:Int=0 To 1 iPos=Instr(sStr, sep, iPos+1) If iPos=0 Then Return 0 Next Return 1 End Method Rem bbdoc: Creates a stringstream out of str. about: Seperator defines the characters used to seperate the lines from eachother. End Rem Function Create:TStringStream(str:String, seperator:String=Chr(0)) Local ssTemp:TStringStream = New TStringStream ssTemp.sStr = Replace(seperator+str+seperator,seperator+seperator,seperator) ssTemp.iPos = 1 ssTemp.sep = seperator Return ssTemp End Function End Type Rem bbdoc: Creates a stringstream out of str. about: Seperator defines the characters used to seperate the lines from eachother. End Rem Function CreateStringStream:TStringStream(str:String, seperator:String=Chr(0)) Return TStringStream.Create(str,seperator) End Function Rem bbdoc: Returns 1 if the stringstream comes to an end. about: End Rem Function Eos:Byte(stream:TStringStream) Return stream.Eof() End Function Rem bbdoc: Reads the next line of the stringstream. about: End Rem Function ReadStringLine:String(stream:TStringStream) Return stream.ReadLine() End Function Rem bbdoc: Writes a line after the last read line. about: End Rem Function WriteStringLine:String(stream:TStringStream, ln:String) Return stream.WriteLine(ln) End Function Rem bbdoc: Sets the position of the cursor in the StringStream. about: Returns 0 if there are less lines then nr. End Rem Function SetStringPos:Byte(stream:TStringStream, nr:Int) Return stream.SetPos(nr) End Function BeispielCode: [AUSKLAPPEN] SuperStrict Import DAK.StringStream Local test:String="hallo~nich~nbin~nein~ntest" Local stream:TStringStream=CreateStringStream(test,"~n") While Not Eos(stream) Print ReadStringLine(stream) Wend ich weiß, es ist nichts großes, aber ich habs für 2 projekte gebraucht und hab mir gedacht, vll kanns noch iwer brauchen... |
||
Gewinner der 6. und der 68. BlitzCodeCompo |
![]() |
BtbN |
![]() Antworten mit Zitat ![]() |
---|---|---|
Und warum hast du das teil nicht von der Stream-Klasse abgeleitet? Das hätte es um einiges einfacher um vielseitig einsetzbarer gemacht. | ||
![]() |
XeresModerator |
![]() Antworten mit Zitat ![]() |
---|---|---|
Geht das nicht mit Bmax eigenen mitteln genauso gut?
Code: [AUSKLAPPEN] SuperStrict
Local test:String="hallo~nich~nbin~nein~ntest" Local arr:String[] = test.Split("~n") For Local i:Int = 0 Until arr.Length Print arr[i] Next End Oder übersehe ich da was? |
||
Win10 Prof.(x64)/Ubuntu 16.04|CPU 4x3Ghz (Intel i5-4590S)|RAM 8 GB|GeForce GTX 960
Wie man Fragen richtig stellt || "Es geht nicht" || Video-Tutorial: Sinus & Cosinus THERE IS NO FAIR. THERE IS NO JUSTICE. THERE IS JUST ME. (Death, Discworld) |
![]() |
DAK |
![]() Antworten mit Zitat ![]() |
---|---|---|
@btbn: magst recht haben... nur müsst ich dazu nicht funktionen wie ReadLine oder so anpassen?
kann man in bmax overloaden? oder wie würdest dus sonst lösen? @xerxes: könnte auch funktionieren... egal... |
||
Gewinner der 6. und der 68. BlitzCodeCompo |
![]() |
BtbN |
![]() Antworten mit Zitat ![]() |
---|---|---|
Du könntest due funktionen ganz weglassen, da die Stream-Klasse sie schon mitbringt. Du must nur Read un Write implementieren, welches einen belibig großen Daten-Block liest/schreibt und in einen Buffer packt. | ||
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group