Reading contents from Ace editor

265 views
Skip to first unread message

pravin nagare

unread,
Feb 28, 2012, 5:53:37 AM2/28/12
to ace-d...@googlegroups.com
I am using Ace editor and using the command editor.getSession().getValue() to read from Ace.
This works but while reading it contains the line numbers displayed on the editor.. Also when i send the read lines to the server and try to save the code there is some unicode to ascii conversion taking place.

Eg:-

My Code:-

#include<stdio.h>

void main()
{
    char str[30];
    printf("Hello");
    scanf("%s",str);
    printf("%s",str)

The way it gets stored after reading from Ace.
Also on my browser the contents above look like this..

12345678910 #include<stdio.h>void main(){    char str[30];    printf("Hello");    scanf("%s",str);    printf("%s",str)} 

This is the error i am getting on the server.
UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position 30: ordinal not in range(128)
Please reply to it as early as possible. I need this urgently.
--
Thanx and regards,

Pravin Nagare
http://pravinnagare.blogspot.com/

JoopR

unread,
Feb 29, 2012, 2:40:52 PM2/29/12
to Ajax.org Cloud9 Editor (Ace)
I replied before but do not see my post. Hope this message makes it.
What you can do is apply encodeURI to the result of
editor.getSession().getValue().
Server side, you'll have to decode, of course.
It solves my problem.
What happened is that Ace (or Chrome) convert 'difficult' characters
to encoded strings. E.g.
é
will be encoded as:
%C3%A9
However, if the server does not understand this (and my eXist XML
database server did not when Chrome posts the data), it understands C3
as à and A9 as ©, so server side the text reads:
é
(the % signs are ignored).
By explicitly encoding the string in my own javascript code,
apparently the server leaves the string intact and my own code can
decode it correctly.
Joop

On Feb 28, 11:53 am, pravin nagare <nagarepravi...@gmail.com> wrote:
> I am using Ace editor and using the command editor.getSession().getValue()
> to read from Ace.*
> *This works but while reading it contains the line numbers displayed on the

Phrogz

unread,
Mar 2, 2012, 2:24:50 PM3/2/12
to ace-d...@googlegroups.com
On Tuesday, February 28, 2012 3:53:37 AM UTC-7, Pravin Nagare wrote:
I am using Ace editor and using the command editor.getSession().getValue() to read from Ace.
This works but while reading it contains the line numbers displayed on the editor.. Also when i send the read lines to the server and try to save the code there is some unicode to ascii conversion taking place.

This is covered on other threads. The problem occurs if you call var editor = ace.editor('myid'); more than once. You need to ensure that you call this function exactly once for each editor.
Reply all
Reply to author
Forward
0 new messages