Please enable JavaScript to view this site.

Knowledge Base

Navigation: Scripting Language > Functions

splitstring

We've made some changes. Use 'Ctrl-F5' to clear your browser cache.
Scroll Prev Top Next More

Splits a long string into a series of substrings, where the substrings are stored in a cell (i.e., string) array.

 

Supported Product: FDTD, MODE, DEVICE, INTERCONNECT

 

Syntax

Description

s2 = splitstring(s1,endl);

Split the string S1 into a series of strings, using the end of line character as the delimiter between strings. S2 is a cell array.

 

Example

Use the splitstring command to get the contents of a directory in a cell (i.e., string) array. Then loop through the array looking for all FDTD Solutions project files (.fsp).

files = splitstring(dir,endl);        # directory contents in a cell (string) array

for(i=1:length(files)) {           # loop over all files

 if (findstring(files{i},"fsp") != -1) {  # look for 'fsp' files

  if (fileexists(files{i})) {       # check if the file exists (ie. it's a file and not a directory)

   ?files{i};               # output file name

   load(files{i});            # load file

  }

 }

}

 

A similar example for getting the names of all monitors in a simulation. Loop through all monitors, checking if they contain a result named 'E'.  If so, save that data to a file.

mNames = splitstring(getresult,endl);

 

for (i=1:length(mNames)) {

 if (haveresult(mNames{i},"E")) {

  E=getresult(mNames{i},"E");   # get a result from that monitor

 } else {

  E = mNames{i} + " did not contain the specified data.";

 }

 filename = "file"+num2str(i);

 savedata(filename,E);     # save data to ldf files

}

 

See Also

Functions, length, substring, findstring, replace, str2num, num2str, cell, dir, getresult, lower, upper, toscript

Copyright Lumerical Inc. | Privacy | Site Map