How do I convert a YailList to String and replace double quotes with single quotes?

YailList is an object that can be only created or the elements inside are just readable.

That means you can only read elements from it.

Object[] list = yailList.toArray(); // converting YailList to array
ArrayList<Object> objects = new ArrayList<>(Arrays.asList((yailList).toArray()));
// Object arrayList

If you're trying to add an element then it's not possible. Instead, you can convert the normal list to YailList.

1 Like

What about this Sir @TIMAI2 ?

You will have to change just few things.

Wouldn't know where to start :wink:

example code starting from here might help me ....

public void NewDrawLineChart( YailList arrayTable) { 
do something to **arrayTable**

Just like this:

// convert YailList to Object[]
Object[] oArr = yailList.toArray();

// convert Object[] to YailList
YailList yailList = YailList.makeList(oArr);

OK, so I convert my yaillist "arrayTable" to an array:

Object[] oArr = arrayTable.toArray();

now I want that array as a string ?

String arrayString = Arrays.toString(oArr);

then I can carry out the replace?

String rString = arrayString.replaceAll("\"", "'");

If this is correct, how do I see my strings arrayString/rString to ensure that the format has been retained?

(I am using intelliJ for IDE)

Now you have to call parse method with that array as argument which will return an array that you have to convert to YailList.

Java is fun, sometimes. :grin: is like trying to catch a black cat in a dark room, when the cat isn't even there :slight_smile:

Let me simplify it.

I just realized that "string" and ""string"" are not same.
So it is not possible to replace " with ' in a string object (because we can't call it a string then).

If you want to replace latter:

public YailList RMethod(YailList yailList){
        Object[] o = parse(yailList.toArray());
        return YailList.makeList(o);
   public Object[] parse(Object[] arr){
        Object[] rArr = new Object[arr.length];
        for (int i=0;i<arr.length;i++){
            Object o = arr[i];
            if (o instanceof String){
                rArr[i] = o.toString().replace("\"","'");
            }else if(o instanceof Object[]){
                Object[] innerArr = (Object[]) o;
                rArr[i] = parse(innerArr);
            }else {
                rArr[i] = o;
        return rArr;
1 Like

Odd, these blocks do it:


and they must come from java code ?

I don't think so.

Print the result on a lable.If it shows 'string' then it means it is actually "'string'". Java/Android does not show " for a string.

I can pass the output of that procedure as a string to the extension and it generates a chart as expected.

I am just working up an example....

See attached a working aia project for a pie chart, and the java code used to build the extension. Note: this uses the blocks procedure to convert the AI2 list to the correct string.

pieChart.aia (7.9 KB) (3.2 KB)

also Google Charts pie chart link:

And extension passes that value to js which is run in WebView.
There are some issues with string conversion between Java and JavaScript.
When you run a js query in WebView to return a string result then you will get that value as already escaped (wrapped in ").
Similarly when you pass a string either wrapped in " or ', that's actually treated as String in JavaScript.
For example, see this snippet from @Taifun (He can shed more light on this topic):

So to conclude this I would say "'string'" (Java) is treated as "string" in JavaScript and "string" (JavaScript) is treated as ""string"" in Java.

Not sure if this is relevant here.

The String htmlcode is constructing a long string of html to be set to file which is then run in a webviewer.
All I want to do is add a string as a variable to that html. As you have seen this works if I send a string by converting the list in the app, but it would be better to get users to simply add the list to the extension blocks, and then convert the "list" (whatever it is) to a string in the java code.

Java, for whatever reason, does not appear to want to do this, without having to iterate over the items in the list, even though this appears trivial when using blocks.....

1 Like

Only method which I can think is going to work is to iterate over each item and wrap that in ' .
Or you actually don't need to do anything.Because " and ' are same in JavaScript.

1 Like

Yes, that appears to work OK, which gets me down to this:


1 Like

In fact this works as well:

in which case this whole topic was "much ado about nothing"

:smiley: :smiley:

1 Like

Many thanks to everyone today for chipping in and having a go, @oseamiya, @Kumaraswamy, @vknow360, and @shreyash.

Through trial and error, prompted by your inputs, I discovered that by setting the "list" to a String in the Simple Function, it was automatically converted it to a string, and with @vknow360 's help found that I could ignore the " that I wanted to be ' . All is well, although I could be a lot further along if I had found this in the first place. Oh well :wink:


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.