[Pas2js] How to split a string using an array as separator?

silvioprog silvioprog at gmail.com
Fri Oct 4 23:11:48 CEST 2019


Hi.

In pure JS, we can split a string using an array as separator (please see
"Splitting with an array as separator" here
<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split>),
e.g.:

var s = 's:foo.bar';
var a = s.split(/[:\.]/);

console.log(a);
(3) ["s", "foo", "bar"]

So, is there any trick to do something like this in pure Pascal? I tried:

A := TJSString(S).split([':', '.']); // error at transpile time
A := TJSString(S).split(':', '.'); // error at transpile time
A := TJSString(S).split('/[:.]/'); // the JS got only a static string

Since the TJSString.split() signature allows only a static string as first
parameter, calls like those above don't work at all, then as workaround I
solved it using an asm block, however, it would be nice to allow pure
Pascal in that.

Thanks in advance for any help!

--
Silvio Clécio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/pas2js/attachments/20191004/5cebaf4a/attachment.html>


More information about the Pas2js mailing list