# Clean up text from paste (webapp)

**URL:** <https://forum.xojo.com/t/clean-up-text-from-paste-webapp/42076>\
**Category:** General\
**Created:** [February 14, 2018, 8:58pm UTC](https://forum.xojo.com/t/clean-up-text-from-paste-webapp/42076 "2018-02-14T20:58:00Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Helge\_Tjelta](https://forum.xojo.com/user_avatar/forum.xojo.com/helge_tjelta/32/193_2.png) [@Helge\_Tjelta](https://forum.xojo.com/u/Helge_Tjelta)\
**Post date:** [February 14, 2018, 8:58pm UTC](https://forum.xojo.com/t/clean-up-text-from-paste-webapp/42076/1 "2018-02-14T20:58:00Z")

</div>

Hi, I have an web-app, and when a user paste text from Outlook(mac) into my textarea, I have a problem, reading it back again from the database… So I suspect it has something to do with characters… I get EOF error all the time… so I have:

“chips?  
F, S”

as text, and a hex dump is: …63…68…69…70…73…2028…46…2C…20…53  
But look right after 73 (that is the S), there is a 20 for space, and 28 for a start parantese, but is it not in my text and it somehow backspace a step… how can I spot this and how can I get rid of this error…

I’m out of options now… have searched a lot…

please help.

the whole text dump is:

Meny 3  
Forrett  
Tartar av økologisk laks med crudité av eple, rødløk og fennikel. Wasabimajones og sesamchips?F, Su,Se,E,G(hvete)  
Hovedrett  
Indre let med bakte småpoteter, urtestekt sopp og babyspinat, sellerikrem. Rødvinssaus?Melk,Se?  
Dessert  
Sitronmousse med lemoncurd,  
bringebærcoulis, bær og sorbet  
E,Melk,G(hvete)

and contins this error at least twise…

---

<div class="post-metadata">

**Author:** ![Roger\_Clary](https://forum.xojo.com/letter_avatar_proxy/v4/letter/r/eada6e/32.png) [@Roger\_Clary](https://forum.xojo.com/u/Roger_Clary)\
**Post date:** [February 14, 2018, 9:48pm UTC](https://forum.xojo.com/t/clean-up-text-from-paste-webapp/42076/2 "2018-02-14T21:48:23Z")

</div>

How are you reading/writing to the DB?  
Are you specifying encoding both in and out?

---

<div class="post-metadata">

**Author:** ![Helge\_Tjelta](https://forum.xojo.com/user_avatar/forum.xojo.com/helge_tjelta/32/193_2.png) [@Helge\_Tjelta](https://forum.xojo.com/u/Helge_Tjelta)\
**Post date:** [February 15, 2018, 9:52am UTC](https://forum.xojo.com/t/clean-up-text-from-paste-webapp/42076/3 "2018-02-15T09:52:29Z")

</div>

Hi Roger, it is my listbox that causes the problems. Not the DB… but I have tried now with encodings to and from DB, but no help.

From DB:  
encTxt = session.curs\_punkt.Field( “Program” ).GetString()  
encTxt = encTxt.ConvertEncoding(Encodings.UTF8)  
cLB.lb.Cell(cLB.lb.LastIndex,3)=encTxt

to DB:  
encTxt = ta(feltnr).text.ConvertEncoding(Encodings.UTF8)  
session.mTbl\_Punkt.field(“program”).SetString(encTxt)

encTxt is a string.

But still no go…

How to strip out NON-characters?

---

<div class="post-metadata">

**Author:** ![Helge\_Tjelta](https://forum.xojo.com/user_avatar/forum.xojo.com/helge_tjelta/32/193_2.png) [@Helge\_Tjelta](https://forum.xojo.com/u/Helge_Tjelta)\
**Post date:** [February 15, 2018, 10:04am UTC](https://forum.xojo.com/t/clean-up-text-from-paste-webapp/42076/4 "2018-02-15T10:04:24Z")

</div>

Well, using this:  
Dim c as TextConverter  
encTxt = session.mTbl\_Punkt.field(“Program”).GetString()  
c=GetTextConverter(Encodings.UTF8, GetTextEncoding(0))  
encTxt=c.convert(encTxt)

for both the listbox and textarea, when showing the text worked…

So, then I’m good for now… thengs Roger, for pointing me in the encoding direction… (I have never had to use encodings before…)

---

<div class="post-metadata">

**Author:** ![Tobias\_Bussmann](https://forum.xojo.com/user_avatar/forum.xojo.com/tobias_bussmann/32/297_2.png) [@Tobias\_Bussmann](https://forum.xojo.com/u/Tobias_Bussmann)\
**Post date:** [February 15, 2018, 1:24pm UTC](https://forum.xojo.com/t/clean-up-text-from-paste-webapp/42076/5 "2018-02-15T13:24:10Z")

</div>

> [@373579:@Helge Tjelta](#):
>
> there is a 20 for space, and 28 for a start parantese, but is it not in my text and it somehow backspace a step

are you sure 2028 isn’t the codepoint 2028 which is a Unicode “LINE SEPARATOR” and could just be Replaced with an EndOfLine?

> [@373579:@Helge Tjelta](#):
>
> web-app, and when a user paste text from Outlook(mac) into my textarea, I have a problem, reading it back again from the database… So I suspect it has something to do with characters… I get EOF error all the time…

this is most certainly an occurrence of \<[https://xojo.com/issue/35919](https://xojo.com/issue/35919)\>  
While Xojo refuses to understand it as a bug, you can circumvent easily it with `mySting.ReplaceAllB(Encodings.UTF8.Chr(8232), EndOfLine)` (old Framework) but need to do this with each and every value being passed as an AJAX request to the browser.

---

<div class="post-metadata">

**Author:** ![Helge\_Tjelta](https://forum.xojo.com/user_avatar/forum.xojo.com/helge_tjelta/32/193_2.png) [@Helge\_Tjelta](https://forum.xojo.com/u/Helge_Tjelta)\
**Post date:** [February 16, 2018, 8:23am UTC](https://forum.xojo.com/t/clean-up-text-from-paste-webapp/42076/6 "2018-02-16T08:23:09Z")

</div>

Hi tobias, I’ll try yours, but why in the code do you use chr(8232) and not 2028 ? or is it something else ?

---

<div class="post-metadata">

**Author:** ![Tobias\_Bussmann](https://forum.xojo.com/user_avatar/forum.xojo.com/tobias_bussmann/32/297_2.png) [@Tobias\_Bussmann](https://forum.xojo.com/u/Tobias_Bussmann)\
**Post date:** [February 16, 2018, 8:54am UTC](https://forum.xojo.com/t/clean-up-text-from-paste-webapp/42076/7 "2018-02-16T08:54:44Z")

</div>

the Unicode codepints that don’t need escapeing in JSON but have a special meaning in Javascript (thus needing escaping otherwise you see the error) are exactly U+2028 and U+2029. These codepoints are encoded in UTF8 at decimal position 8232 and 8233, see [here](http://decodeunicode.org/en/u+2028).

`Value = ReplaceAllB(Value, Encodings.UTF8.Chr(8232), "\\u2028")
Value = ReplaceAllB(Value, Encodings.UTF8.Chr(8233), "\\u2029")
`  
It would really help if Xojo would add these two lines where the framework does the other JS escaping stuff already internally.  
For all kind of Unicode analysis stuff, I can recommend the Tool ‘[Unicode Checker](http://earthlingsoft.net/UnicodeChecker/)’ for macOS.

---

<div class="post-metadata">

**Author:** ![Helge\_Tjelta](https://forum.xojo.com/user_avatar/forum.xojo.com/helge_tjelta/32/193_2.png) [@Helge\_Tjelta](https://forum.xojo.com/u/Helge_Tjelta)\
**Post date:** [February 16, 2018, 8:58am UTC](https://forum.xojo.com/t/clean-up-text-from-paste-webapp/42076/8 "2018-02-16T08:58:56Z")

</div>

So If I use it before storing into database, I will not need to do it again when displaying into listbox or textareas ?

---

<div class="post-metadata">

**Author:** ![Tobias\_Bussmann](https://forum.xojo.com/user_avatar/forum.xojo.com/tobias_bussmann/32/297_2.png) [@Tobias\_Bussmann](https://forum.xojo.com/u/Tobias_Bussmann)\
**Post date:** [February 16, 2018, 9:24am UTC](https://forum.xojo.com/t/clean-up-text-from-paste-webapp/42076/9 "2018-02-16T09:24:29Z")

</div>

> [@373827:@Helge Tjelta](#):
>
> So If I use it before storing into database, I will not need to do it again when displaying into listbox or textareas ?

correct - if you filter the input before you save it, you don’t need to escape it before displaying. But in that case the original value would be lost. You can replace it with EndOfLine, something similar, or depending on the source even `""` may be appropriate.  
Be careful if you try to display it directly again w/o storing it: Something like `WebLabel1.Text = WebTextArea1.Text` would not be possible unaltered.  
The replacement of `\\u2028` would be the valid JSON escape sequence for the unaltered character but this need to be done on display.

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 7:06pm UTC](https://forum.xojo.com/t/clean-up-text-from-paste-webapp/42076/10 "2020-10-29T19:06:18Z")

</div>


