diff --git a/docs/reference/text/to-string.md b/docs/reference/text/to-string.md new file mode 100644 index 00000000..5377b1a0 --- /dev/null +++ b/docs/reference/text/to-string.md @@ -0,0 +1,7 @@ +# to string + +Converts a value into a text representation. + +```sig +toString(123) +``` \ No newline at end of file diff --git a/libs/core/_locales/core-jsdoc-strings.json b/libs/core/_locales/core-jsdoc-strings.json index b4cbff92..bf59c02c 100644 --- a/libs/core/_locales/core-jsdoc-strings.json +++ b/libs/core/_locales/core-jsdoc-strings.json @@ -549,5 +549,7 @@ "serial.writeString": "Send a piece of text through the serial connection.", "serial.writeValue": "Write a name:value pair as a line to the serial port.", "serial.writeValue|param|name": "name of the value stream, eg: x", - "serial.writeValue|param|value": "to write" + "serial.writeValue|param|value": "to write", + "toString": "Convert any value to a string", + "toString|param|value": "value to be converted to a string" } \ No newline at end of file diff --git a/libs/core/_locales/core-strings.json b/libs/core/_locales/core-strings.json index e888bb7b..29c08ace 100644 --- a/libs/core/_locales/core-strings.json +++ b/libs/core/_locales/core-strings.json @@ -371,6 +371,7 @@ "serial.writeString|block": "serial|write string %text", "serial.writeValue|block": "serial|write value %name|= %value", "serial|block": "serial", + "toString|block": "convert $value=variables_get(myValue) to string", "{id:category}AnalogInPin": "AnalogInPin", "{id:category}AnalogOutPin": "AnalogOutPin", "{id:category}Array": "Array", diff --git a/libs/core/control.ts b/libs/core/control.ts index 670fd1b2..a0403cb7 100644 --- a/libs/core/control.ts +++ b/libs/core/control.ts @@ -53,3 +53,14 @@ namespace control { //% shim=pxtrt::runtimeWarning export function runtimeWarning(message: string) { } } + +/** + * Convert any value to a string + * @param value value to be converted to a string + */ +//% help=text/to-string weight=1 +//% block="convert $value=variables_get(myValue) to string" +//% blockId=variable_to_string blockNamespace="text" +function toString(value: any): string { + return "" + value; +} \ No newline at end of file