Insert an hidden character in text string using JavaScript

A

Amol

How to use an hidden character in text string using JavaScript.There
is one text string which i read and writes back with the hidden
character in it (so rewritten text looks same as the original text
though it comtains the hidden character), so that next time i read the
text i can come to know that this text is aleady read as it contains
the hidden character

Eg)

"<html>
<body>
<div>
This is a simple text
</div>
</body>
</html>"

I am trying to parse the div and extract the contents of the div, and
insert an hidden character to the text and rewrite the text to the div
again using JavaScript.

I just want to know which hidden character should i use to insert into
the text ?
How to write the hidden character into the text ?
 
E

Evertjan.

Amol wrote on 20 mei 2009 in comp.lang.javascript:
How to use an hidden character in text string using JavaScript.

What is a hidden character in a string?
A string just has characters, meseems.

Why would you want to do that?

Is this a school assignment???
There
is one text string which i read and writes back with the hidden
character in it (so rewritten text looks same as the original text
though it comtains the hidden character), so that next time i read the
text i can come to know that this text is aleady read as it contains
the hidden character

myString = myString.substr(0,pos) + myHidden + myString.substr(pos+1);
Eg)

"<html>
<body>
<div>
This is a simple text
</div>
</body>
</html>"

I am trying to parse the div

You cannot parse a div, you only can parse a string with javascript.
and extract the contents of the div, and

The other way around:
You should firste extract a string from the content of the div,
and then you could manipulate that string:

var myString = document.getElementByid('divId').innerHTML;

insert an hidden character to the text and rewrite the text to the div
again using JavaScript.

document.getElementByid('divId').innerHTML = myString;
I just want to know which hidden character should i use to insert into
the text ?

Me too!
See the questions above and please answer them.

Are you sure this is not a school assignment???
How to write the hidden character into the text ?

See above.
 
A

Amol

Amol wrote on 20 mei 2009 in comp.lang.javascript:


What is a hidden character in a string?
A string just has characters, meseems.

Why would you want to do that?

Is this a school assignment???


myString = myString.substr(0,pos) + myHidden + myString.substr(pos+1);






You cannot parse a div, you only can parse a string with javascript.


The other way around:
You should firste extract a string from the content of the div,
and then you could manipulate that string:

var myString = document.getElementByid('divId').innerHTML;


document.getElementByid('divId').innerHTML = myString;


Me too!
See the questions above and please answer them.

Are you sure this is not a school assignment???


See above.



Hi Evertjan
Thanks for your reply
Yes this is an school assignment

I just want to know which hidden character should i use to insert into
the text ?

Once i get the contents of the div, i am trying to append some value
to it (which will not be visible like ASCII NULL character "O") so
that next time i come and check the text, i will get the value with
the hidden value appended.
 
T

Thomas 'PointedEars' Lahn

Amol said:

For goodness sake, trim your quotes to the relevant minimum!

[...]
Yes this is an school assignment

You're just about to fail it ...
I just want to know which hidden character should i use to insert into
the text ?

See? Test failed. The purpose of the assignment is that you acquire
knowledge independent of others; that is, first think about what is relevant
to the problem at hand and then find resources to solve it.

FWIW: This has little to do with ECMAScript implementations. You will find
the answer in the HTML 4.01 Specification, of course. Good luck.


PointedEars
 
E

Evertjan.

Thomas 'PointedEars' Lahn wrote on 21 mei 2009 in comp.lang.javascript:
Amol wrote: [..]
[...]
Yes this is an school assignment

You're just about to fail it ...
I just want to know which hidden character should i use to insert
into the text ?

See? Test failed. The purpose of the assignment is that you acquire
knowledge independent of others; that is, first think about what is
relevant to the problem at hand and then find resources to solve it.

FWIW: This has little to do with ECMAScript implementations. You will
find the answer in the HTML 4.01 Specification, of course. Good luck.

More to the points Pointed made:

There are no hidden characters in javascript strings!
Javascript strings are just strings of numeric [32 bit] 'words'.
They are only 'text' strings by the way they are used by you.

Do not let others do your assignments, Amol,
even if you pass, you will fail miserably later on.
 
T

Tim Streater

Evertjan. said:
Thomas 'PointedEars' Lahn wrote on 21 mei 2009 in comp.lang.javascript:
Amol wrote: [..]
[...]
Yes this is an school assignment

You're just about to fail it ...
I just want to know which hidden character should i use to insert
into the text ?

See? Test failed. The purpose of the assignment is that you acquire
knowledge independent of others; that is, first think about what is
relevant to the problem at hand and then find resources to solve it.

FWIW: This has little to do with ECMAScript implementations. You will
find the answer in the HTML 4.01 Specification, of course. Good luck.

More to the points Pointed made:

There are no hidden characters in javascript strings!
Javascript strings are just strings of numeric [32 bit] 'words'.
They are only 'text' strings by the way they are used by you.

Do not let others do your assignments, Amol,
even if you pass, you will fail miserably later on.

Perhaps by "invisible" he means "non-printing" so it wouldn't show on
the screen.
 
T

Thomas 'PointedEars' Lahn

Tim said:
Evertjan. said:
[...]
There are no hidden characters in javascript strings!
Javascript strings are just strings of numeric [32 bit] 'words'.
They are only 'text' strings by the way they are used by you.
[...]

Perhaps by "invisible" he means "non-printing" so it wouldn't show on
the screen.

The answer is to be found in the Unicode standard, then.

Please trim your quotes to the relevant minimum.


PointedEars
 
T

Tim Streater

Thomas 'PointedEars' Lahn said:
Tim said:
Evertjan. said:
[...]
There are no hidden characters in javascript strings!
Javascript strings are just strings of numeric [32 bit] 'words'.
They are only 'text' strings by the way they are used by you.
[...]

Perhaps by "invisible" he means "non-printing" so it wouldn't show on
the screen.

The answer is to be found in the Unicode standard, then.

Please trim your quotes to the relevant minimum.

No.
 
T

Thomas 'PointedEars' Lahn

Tim said:
Thomas said:
Tim said:
:
[...]
There are no hidden characters in javascript strings!
Javascript strings are just strings of numeric [32 bit] 'words'.
They are only 'text' strings by the way they are used by you.
[...]
Perhaps by "invisible" he means "non-printing" so it wouldn't show on
the screen.
The answer is to be found in the Unicode standard, then.

Please trim your quotes to the relevant minimum.

No.

"No" to what?


PointedEars

P.S.: <http://www.jibbering.com/faq/faq_notes/clj_posts.html#ps1Trim>
 
E

Evertjan.

Tim Streater wrote on 21 mei 2009 in comp.lang.javascript:
There are no hidden characters in javascript strings!
Javascript strings are just strings of numeric [32 bit] 'words'.
They are only 'text' strings by the way they are used by you.

Do not let others do your assignments, Amol,
even if you pass, you will fail miserably later on.

Perhaps by "invisible" he means "non-printing" so it wouldn't show on
the screen.

Why secondguessing the OP's teachter's possible lack of exactness?
 
E

Evertjan.

Thomas 'PointedEars' Lahn wrote on 21 mei 2009 in comp.lang.javascript:
The answer is to be found in the Unicode standard, then.

Please trim your quotes to the relevant minimum.

Javascript strings do not "contain" Unicode.

Some javascript functions, like regex ones, might assume it,
but writing to html certainly does no such thing.
 
D

Dr J R Stockton

In comp.lang.javascript message <d8ba3b16-ed5e-43e6-8d63-e1e9a61e6e8c@v3
5g2000pro.googlegroups.com>, Wed, 20 May 2009 03:49:07, Amol
I just want to know which hidden character should i use to insert into
the text ?

If you are sure that one of the characters of the string is a space,
\x20, then you can replace it with a non-breaking space, \xA0.
 
T

Thomas 'PointedEars' Lahn

Dr said:
Amol posted:

If you are sure that one of the characters of the string is a space,
\x20, then you can replace it with a non-breaking space, \xA0.

However, while a raw non-breaking space character could watermark the text,
it is far from being hidden, and even in an HTML document exchanging a space
character for it is supposed to make a difference in rendering.

<http://www.w3.org/TR/REC-html40/struct/text.html#whitespace>


PointedEars
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]>
There are no hidden characters in javascript strings!
Javascript strings are just strings of numeric [32 bit] 'words'.
They are only 'text' strings by the way they are used by you.

The OP seems to want them to be not visible in the display. Several
Unicode characters have that property.

Consider ZWNJ, ZWJ, whichever one of LRM & RLM has no current effect (or
both if they are understood but not supported.
See <http://www.unicode.org/charts/PDF/U2000.pdf> and consider others on
that page. The more esoteric ones need to be checked for browser
compatibility.

Also, consider A and &Alpha; , B and &Beta; . They may in some fonts
have distinguishable glyphs; but the difference should be inconspicuous.

Of course, that will fail if the teacher uses a screen reader for audio
output.

Then, while not a single character, inserting <z> or <span> </span>
would serve.

The OP might be able to add an unknown property to the <div>; that seems
more elegant than bodging the text.
 
T

Thomas 'PointedEars' Lahn

Matthias said:
Evertjan. said:
Javascript strings are just strings of numeric [32 bit] 'words'.

Ah, no, 16 bit.

If one understands a "Javascript" character as "string" (and I really don't
know what the both of you are talking about here exactly) then "16 bit" is
not correct either. Using UTF-16 for ECMAScript primitive string values
internally merely means that one Unicode code unit is 16 bit wide. However,
one Unicode character might need several code units to be encoded in a UTF,
and so more than 16 bits.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top