help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Converting (more or less) arbitrary strings to valid variable names


From: Bård Skaflestad
Subject: Converting (more or less) arbitrary strings to valid variable names
Date: Mon, 19 Nov 2012 21:47:41 +0000

All,

In the long-running thread on "C-equivalent" structure (array) initialisation, 
someone asked of a way of converting an arbitrary string into a valid variable 
name.  Unfortunately, I deleted the e-mail too early so I cannot give proper 
attribution here.

Still, I may be able to provide at least a partial answer to the inquiry.  The 
built-in function 'genvarname', present since at least Octave 3.2.3,  does 
solve some of this problem.  Here's an example

    > genvarname ("0  _f00  ba'r")
    ans = _0___f00__ba_r

Obviously, the normal restrictions on variable names apply (string restricted 
to "namelengthmax" characters being the most severe).


I hope this helps a little bit.

Sincerely,
-- 
Bård Skaflestad
SINTEF ICT, Applied Mathematics

reply via email to

[Prev in Thread] Current Thread [Next in Thread]