Inform me () when using this script or encorporating it in a library.
Source code of tostring.pro:
;+
; NAME:
; TOSTRING
; PURPOSE:
; Converts argument into a string according to desired format
; and trims white space.
; CALLING SEQUENCE:
; toString, value, format=format[, notrim=notrim]
; EXAMPLES:
; print, toString(sqrt(2d), f='D6.4')
; prints 1.4142
; KEYWORDS:
; value = scalar or array to apply the formatting to
; format = see the STRING function, although the round brackets
; are not necessarily required
; notrim = do not trim the whitespace
; MODIFICATION HISTORY:
; Before 05/06/2007 Written by Eduard Westra
;-
FUNCTION toString, value, format=format, notrim=notrim
IF KEYWORD_SET(format) THEN BEGIN
tformat = (STRCMP(STRMID(format, 0, 1), '(') EQ 0 ? '(': '')+ $
format+ $
(STRCMP(STRMID(format, STRLEN(format)-1, 1), ')') EQ 0 ? ')' : '')
ENDIF
RETURN, (N_ELEMENTS(notrim) NE 0 ? $
STRING(value, format=tformat) : $
STRTRIM(STRING(value, format=tformat),2))
END