how to get a part of file(non-binary)?

Multimedia Builder (Legacy Forum)
Post Reply
TheCableGuy
Posts: 6
Joined: Tue Apr 17, 2012 3:42 pm
Contact:

how to get a part of file(non-binary)?

Post by TheCableGuy »

Suppose a file containing something like this:

Code: Select all

Sec1 :OPTION {
  value=1;
}
Sec2 :OPTION1 @OPTION2 {
  Blablabla
  blablabla
}
Sec3 :OPTION {
  value=2;
}
how to extract SEC2 ?
from '{' to '}'

dgilmour
Posts: 531
Joined: Fri Oct 22, 2010 11:29 am
Location: Moskva, Rusko
Contact:

Re: how to get a part of file(non-binary)?

Post by dgilmour »

Reading about string functions and using them in your project. Something like POS and StrCopy should help.

Delboy
Posts: 829
Joined: Sat Oct 23, 2010 9:28 am
Location: Reading, UK
Contact:

Re: how to get a part of file(non-binary)?

Post by Delboy »

Sergeys correct you should read the help file.
but study this code you will get the idea of how it works.

using below as file C:\test.ini

Code: Select all

Sec1 :OPTION {
  value=1;
}
Sec2 :OPTION1 @OPTION2 {
  Blablabla
  blablabla
}
Sec3 :OPTION {
  value=2;
}
use below code to get the stored data

Code: Select all

keyword_start$[1] = '{'
keyword_end$[1] = '}'
keyword$[1] = 'Sec1'
keyword$[2] = 'Sec2'
keyword$[3] = 'Sec3'
keyword$[4] = 'Sec4'
OpenFile$ = 'c:\test.ini'
content$ = StrFromFile(OpenFile$,1,-1)
p = POS(keyword$[2],content$)
l = LEN(content$)
If (p) Then
  p = p  + LEN(keyword$[2])
  copy_from$ = StrCopy(content$,p,l)
  start = POS(keyword_start$[1],copy_from$)
  finish = POS(keyword_end$[1],copy_from$)
  If (finish) Then
    For i = 1 To 1
      start = start + LEN(keyword_start$[1])
      finish = finish - LEN(keyword_end$[1])
      copy$ = StrCopy(copy_from$,start,finish)
      found$ = GetArrayItem(copy$,},i)
      Message("found$","")
    End
  Next i
End

Cheers
DMFX Player v3.0.9.7 Released 02/03/2016

Nigg
Posts: 57
Joined: Thu Apr 14, 2011 2:10 pm

Re: how to get a part of file(non-binary)?

Post by Nigg »

The solution is nice, but I'm looking for a way to put two variables in one section or to use a separator to store the text in two variables.

For example:

myvar myvarValue {
blah=Blablah
}

Anybody got any ideas?

dgilmour
Posts: 531
Joined: Fri Oct 22, 2010 11:29 am
Location: Moskva, Rusko
Contact:

Re: how to get a part of file(non-binary)?

Post by dgilmour »

Nigg wrote:Anybody got any ideas?
Use string functions - this is what I can say from your description. What part of your task seems difficult?

Nigg
Posts: 57
Joined: Thu Apr 14, 2011 2:10 pm

Re: how to get a part of file(non-binary)?

Post by Nigg »

I'm not quite sure how best to do this with the given functions. Count to the separator in a loop? And then cut off the length and save it to the first variable? Isn't there an easier way to do this?

Edit: Using an array now , thanks anyways

dgilmour
Posts: 531
Joined: Fri Oct 22, 2010 11:29 am
Location: Moskva, Rusko
Contact:

Re: how to get a part of file(non-binary)?

Post by dgilmour »

If you mean so called string arrays, then yes, there are two neat functions to work with them.

Post Reply