Nasal library functions: Difference between revisions

Jump to navigation Jump to search
Line 14: Line 14:


== subvec() ==
== subvec() ==
Extract items of a vector (equivalent to the left() function for a string)
Extract items of a vector - equivalent to the left() function for a string
 
Example :
Example :


<syntaxhighlight lang="nasal" enclose="div">
<syntaxhighlight lang="nasal" enclose="div">
var currentPath = "/home/xxx/yyy/";
var FGRoot = getprop("/sim/fg-root");
print (directory(currentPath));
var filename = "/Aircraft";
var path_files = directory(FGRoot ~ filename);
 
foreach(var key; path_files) {
print(key);
}
</syntaxhighlight>
</syntaxhighlight>
returns : ".", "..", "file1", "file2", "file3"
returns : '''"." , ".." , "Generic", "Instruments", "Instruments-3d", "c172p", "ufo"'''
 


and :
With subvec():


<syntaxhighlight lang="nasal" enclose="div">
<syntaxhighlight lang="nasal" enclose="div">
var currentPath = "/home/xxx/yyy/";
var FGRoot = getprop("/sim/fg-root");
print (subvec(directory(currentPath),2));
var filename = "/Aircraft";
var path_files = subvec(directory(FGRoot ~ filename),2);
 
foreach(var key; path_files) {
print(key);
}
</syntaxhighlight>
</syntaxhighlight>
returns : "file1", "file2", "file3"
returns : '''"Generic", "Instruments", "Instruments-3d", "c172p", "ufo"'''
 


<syntaxhighlight lang="nasal" enclose="div">
<syntaxhighlight lang="nasal" enclose="div">
var currentPath = "/home/xxx/yyy/";
var FGRoot = getprop("/sim/fg-root");
print (subvec(directory(currentPath),3));
var filename = "/Aircraft";
var path_files = subvec(directory(FGRoot ~ filename),3);
 
foreach(var key; path_files) {
print(key);
}
</syntaxhighlight>
</syntaxhighlight>
returns : "file2", "file3"
returns : '''"Instruments", "Instruments-3d", "c172p", "ufo"'''


== delete() ==
== delete() ==
29

edits

Navigation menu