Converting string to char array

55 views
Skip to first unread message

Andrew Dixon

unread,
Apr 14, 2015, 6:55:31 PM4/14/15
to lu...@googlegroups.com
Hi,

I have a string that I need to convert to a char array to pass to a Java object, so if I do this manually I have to do:

exampleVar = javaCast("char[]", ['e','x','a','m','p','l','e']);

However I have the data as a string:

exampleVar = "example";

I've looked over the functions on the luceedocs.org but I can't see one for converting the string to an array, am I missing it or will I have to write a function myself to do this?

So I'm guessing I'm hoping for something like:

exampleVar = "example";
exampleStringArray = stringToArray(exampleVar);
exampleCharArray = javaCast("char[]", exampleStringArray);

Thanks.

Kind regards,

Andrew
about.me
mso - Lucee - Member

Adam Cameron

unread,
Apr 14, 2015, 7:04:33 PM4/14/15
to lu...@googlegroups.com
You don't need a special Lucee function; there's already one in java.lang.String:

exampleVar = "example"
charArray = exampleVar.toCharArray()
dump(variables)

-- 
Adam

Adam Cameron

unread,
Apr 14, 2015, 7:06:27 PM4/14/15
to lu...@googlegroups.com
If - for some reason - you wanted to stick with CML:

cfmlArray =  exampleVar.listToArray("")

But use the toCharArray() version, IMO

-- 
Adam

Michael Offner

unread,
Apr 15, 2015, 2:08:48 AM4/15/15
to lucee
as Adam said, we could also extend the function JavaCast to support this
carr = javaCast("char[]", "Hello World");
can you raise a ticket for it

Micha


--
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/CAG1WijWf7GAx0zdaDO5x-BXv%3Dh16MoZHQk_aRN7VnCZL08HJ8w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Andrew Dixon

unread,
Apr 15, 2015, 2:58:26 AM4/15/15
to lu...@googlegroups.com
Hi Micha,

That would be very useful, I have raised an issue as requested:


Any chance of getting this in 4.5?

Kind regards,

Andrew
about.me
mso - Lucee - Member

Adam Cameron

unread,
Apr 15, 2015, 3:05:29 AM4/15/15
to lu...@googlegroups.com


On Wednesday, 15 April 2015 07:58:26 UTC+1, Andrew Dixon wrote:
Hi Micha,

That would be very useful, I have raised an issue as requested:


Any chance of getting this in 4.5?


I think this is a good tweak to javaCast(). But given you've been given two completely workable solutions that are already there in 4.5, what's the compelling reason to back port it into 4.5? (or, indeed, even specifically prioritise it for 5.0).

-- 
Adam

 

Andrew Dixon

unread,
Apr 15, 2015, 3:42:08 AM4/15/15
to lu...@googlegroups.com
Hi Adam,

I guess not, just the code will be going onto a 4.5 production server that will probably not be updated to 5 anytime in the next 3 - 6 months, so it would say going back and changing the code if it was already available, but there is no compelling reason... I did load it into BitBucket as "minor"... :-)

Kind regards,

Andrew
about.me
mso - Lucee - Member

--
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.

Michael Offner

unread,
Apr 15, 2015, 4:20:19 AM4/15/15
to lucee
normally we have the rule that we only do new features with alpha releases, so this means Lucee>5, but i think it is possible to thread this as a bug... 

Micha

Reply all
Reply to author
Forward
0 new messages