function Split

New to FreeBASIC? Post your questions here.
ptitjoz
Posts: 25
Joined: Jun 24, 2017 8:10
Location: France, centre
Contact:

Re: function Split

Postby ptitjoz » Apr 09, 2018 14:18

Hello
Many things to see to understand. This forum is rich in your contributions and it is difficult for me to understand everything (and English does not help)
Yes, it's true that copying and pasting does not help you to learn well. That's why I'm doing my experiments trying to help you with the documentation and your remarks.

A bit of code that I had fun doing with basic syntax. It is certainly not fast or optimized but as I often say I try to be pragmatic.

Regards

Code: Select all

'Split  version 02

Dim As String s = "aaaa;bbbbbb;ccccc;ddddddd;eeeeee"  'chaine à découper
Dim As String t=s 'chaine de travail
Dim As String d = ";" 'délimiteur
Dim As Integer nb=0 ' nombre d'éléments
Dim As Integer p,i

' Recherche du nombre d éléments pour dimenstionner le tableau
For i=1 To Len(s)
   If Mid(s,i,1)=d Then nb=nb+1
Next

' dimensionnement du tableau
nb=nb+1 ' rajout de 1 pour dernier élément
Dim As String tableau(1 to nb)

' remplissage tableau
For i=1 To nb
   p=instr(t,d)
   tableau(i)= mid(t,1,p-1)
   t=right(t,Len(t)-p)
Next

' Vérification
For i=1 To nb
   Print i,Tableau(i),Len(Tableau(i))
Next
MrSwiss
Posts: 3222
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: function Split

Postby MrSwiss » Apr 09, 2018 14:47

ptitjoz wrote:Yes, it's true that copying and pasting does not help you to learn well.
That depends also, on your preferred *way of learning*.

Downloading OPC (OPC = other peoples code), isn't necessarily a *bad thing*.
Provided, you study the *way its done* and, the reasons, for doing it *this way*.

You might have to have, the <FB-Manual> handy, to figure out yet unknown *KeyWords*.
(this goes, without *spelling it out*, to understand certain techniques used)

Download latest "freebasic_manual.chm": <HERE>
dodicat
Posts: 5913
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: function Split

Postby dodicat » Apr 09, 2018 15:14

Sometimes you'll want a string split by more than one character as a whole deliminator.
For example:

Code: Select all

 
Sub string_split(byval s As String,chars As String,result() As String)
    redim result(0)
    Dim As String var1,var2
Dim As long pst,LC=len(chars)
      #macro split(stri)
    pst=Instr(stri,chars)
    var1="":var2=""
    If pst<>0 Then
    var1=Mid(stri,1,pst-1)
    var2=Mid(stri,pst+LC)
    Else
    var1=stri
End if
    if len(var1) then
    redim preserve result(1 to ubound(result)+1)
    result(ubound(result))=var1
    end if
    #endmacro
   Do
   split(s):s=var2
Loop Until var2=""
End Sub



dim as string s="aaaa123456789bbbbbb123456789ccccc123456789ddddddd123456789eeeeee"
redim as string r()
string_split(s,"123456789",r())
for n as long=lbound(r) to ubound(r)
    print n,r(n)
next
sleep

 


There isn't much help within freeBASIC for the crt functions.
Sometimes examples help to understand. (D.J.Peters and strtok for example)
ptitjoz
Posts: 25
Joined: Jun 24, 2017 8:10
Location: France, centre
Contact:

Re: function Split

Postby ptitjoz » Apr 10, 2018 14:49

MrSwiss wrote:
ptitjoz wrote:Yes, it's true that copying and pasting does not help you to learn well.
That depends also, on your preferred *way of learning*.

Downloading OPC (OPC = other peoples code), isn't necessarily a *bad thing*.
Provided, you study the *way its done* and, the reasons, for doing it *this way*.

You might have to have, the <FB-Manual> handy, to figure out yet unknown *KeyWords*.
(this goes, without *spelling it out*, to understand certain techniques used)

Download latest "freebasic_manual.chm": <HERE>

Hello
I am running Linux and * .chm help does not work.

Would not there be a manual in pdf (or epub) format?

Thank you
fxm
Posts: 9126
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: function Split

Postby fxm » Apr 10, 2018 15:05

ptitjoz wrote:I am running Linux and * .chm help does not work.

Use xchm (or gnochm for gnome)?
dodicat
Posts: 5913
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: function Split

Postby dodicat » Apr 10, 2018 15:13

fxm
Posts: 9126
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: function Split

Postby fxm » Apr 10, 2018 15:30

Or use an online converter to have a newer version.
dodicat
Posts: 5913
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: function Split

Postby dodicat » Apr 10, 2018 15:46

That is the latest version
1.05.0
is it not?
It is from the freebasic home page/downloads 20 minutes ago.

Here is the site I used to convert (very good)
http://www.convertfiles.com/convert/ebook/CHM-to-PDF.html
fxm
Posts: 9126
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: function Split

Postby fxm » Apr 10, 2018 15:51

I thought about convert the daily manual version (.chm) from:
http://users.freebasic-portal.de/stw/builds/
ptitjoz
Posts: 25
Joined: Jun 24, 2017 8:10
Location: France, centre
Contact:

Re: function Split

Postby ptitjoz » Apr 10, 2018 16:57

thank you very much
the xchm crash
I downloaded the pdf it's ok!
Best regards
dodicat
Posts: 5913
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: function Split

Postby dodicat » Apr 10, 2018 17:34

Anyway ptitjoz, your web browser should be able to open .chm files directly.
When I used Linux years ago Firefox and the default browser (can't remember the name), opened the .chm files.
fxm
Posts: 9126
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: function Split

Postby fxm » Apr 11, 2018 13:55

With the CHM Reader extension for FireFox.
dodicat
Posts: 5913
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: function Split

Postby dodicat » Apr 11, 2018 14:13

Must get back to using Linux again.

There was a win 10 update last night.
It managed to wipe out all my internet history links, every last one.

Goodness knows, could you rely on a system like that for anything important?

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 2 guests