Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes


mputstr

write a single text in an open file

Syntax

mputstr(str)
mputstr(str, fid)

Arguments

fid

integer: file identifier returned by mopen(…). -1 (default) stands for the last opened file.

str

Single text to write in the file. Multilingual UTF-8 characters are accepted. str can include special formatting characters like ascii(9) (tab), ascii(10) (newline) and ascii(13) (carriage return). Sequences like "\t", "\n" and "\r" have no special meaning and are written as is.

Description

mputstr(…) writes a character string str in a binary or text file. str is buffered: It is actually written in the file only when closing this one.

Examples

myFile = tempname();
fid = mopen(myFile, "wt");

mputstr("Scilab", fid);
mgetl(myFile) // => []. "Scilab" has been buffered
mputstr(" and Xcos", fid);
mgetl(myFile) // => still []. " and Xcos" added to the buffer

// Only one text can be sent at a once:
mputstr(["Science" ; "Innovation"], fid);     // => error

mclose(fid);
mgetl(myFile) // => "Scilab and Xcos"
mdelete(myFile);

--> mputstr("Scilab", fid);
--> mgetl(myFile) // => []. "Scilab" has been buffered
 ans  =
    []

--> mputstr(" and Xcos", fid);
--> mgetl(myFile) // => still []. " and Xcos" added to the buffer
 ans  =
    []

--> // Only one text can be sent:
--> mputstr(["Science" ; "Innovation"], fid);    // => error
mputstr: Argument #1: Scalar (1 element) expected.

--> mclose(fid);
--> mgetl(myFile)
 ans  =
  "Scilab and Xcos"

Use UTF-8 and special formatting characters:

[tab, nl] = (ascii(9), ascii(10));
myFile = tempname();
fid = mopen(myFile, "wt");

mputstr("Επιστήμη", fid);
mputstr(ascii(10), fid);      // Line feed
mputstr("Τεχνολογία" + nl, fid);
mputstr(tab, fid);           // Heading tab
mputstr("innovation", fid);
mputstr(nl + "Science" + nl + tab + "technology", fid);
mclose(fid);
mgetl(myFile)

mdelete(myFile);
--> mputstr("Επιστήμη", fid);
--> mputstr(ascii(10), fid);      // Line feed
--> mputstr("Τεχνολογία" + nl, fid);
--> mputstr(tab, fid);           // Heading tab
--> mputstr("innovation", fid);
--> mputstr(nl + "Science" + nl + tab + "technology", fid);
--> mclose(fid);
--> mgetl(myFile)
 ans  =
  "Επιστήμη"
  "Τεχνολογία"
  "        innovation"
  "Science"    
  "        technology"

See also

  • mgetstr — ファイルから文字列を読み込む
  • mputl — テキストファイルに文字列を書き込む
  • mgetl — アスキーファイルから行を読み込む
  • mput — 指定したバイナリ形式でバイトまたはワードを書き込む
  • mfprintf — converts, formats, and writes data to a file
  • save — Saves some chosen variables in a binary data file
  • write — フォーマットされたファイルに書き込む
  • csvWrite — CSVファイルを書き込む
Report an issue
<< mputl Files : Input/Output functions mseek >>

Copyright (c) 2022-2023 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Mon Nov 07 15:06:00 CET 2022