"invisible" characters for strings?

  • Thread starter Thread starter VM
  • Start date Start date
V

VM

If I have three exact strings composed of "Hello world", what 'invisible'
char could I add to the string so I can distinguish between them? With
visible characters, it'd look something like this:

"#Hello world"
"@Hello word"
"$Hello world"

I'd like to replace the #, @, $ with invisible characters. These strings
will be displayed in a windows datagrid cell.

Thanks.
 
If I have three exact strings composed of "Hello world", what 'invisible'
char could I add to the string so I can distinguish between them? With
visible characters, it'd look something like this:

"#Hello world"
"@Hello word"
"$Hello world"

I'd like to replace the #, @, $ with invisible characters. These strings
will be displayed in a windows datagrid cell.

Tabs? Spaces?

Anyway, you can distinguish between them with their reference, provided that
the strings are dynamically assembled. Multiple strings with the same
content are interned so that

object.ReferenceEquals("Hello World", "Hello World")

returns true, but

string d = "d";
object.ReferenceEquals("Hello World", "Hello Worl"+d)

should return false. Lets hope the compiler doesn't optimize the
concatenation away.

another way would to create a new class which holds the string and if you
create multiple objects of that class you can alway distinguish between
them.
 
Seems like a confusing post. Strings with the same content are not
necessarily interned. For the most part, only string literals are interned
while all other strings are left to their different references and storage
in memory.

As long as those Hello World's are coming out of a file, database,
user input, or pretty much anything other than being hard-coded into
the source, you are likely to use reference equality to tell the difference.

--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

cody said:
If I have three exact strings composed of "Hello world", what 'invisible'
char could I add to the string so I can distinguish between them? With
visible characters, it'd look something like this:

"#Hello world"
"@Hello word"
"$Hello world"

I'd like to replace the #, @, $ with invisible characters. These strings
will be displayed in a windows datagrid cell.

Tabs? Spaces?

Anyway, you can distinguish between them with their reference, provided that
the strings are dynamically assembled. Multiple strings with the same
content are interned so that

object.ReferenceEquals("Hello World", "Hello World")

returns true, but

string d = "d";
object.ReferenceEquals("Hello World", "Hello Worl"+d)

should return false. Lets hope the compiler doesn't optimize the
concatenation away.

another way would to create a new class which holds the string and if you
create multiple objects of that class you can alway distinguish between
them.

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
 
Seems like a confusing post. Strings with the same content are not
necessarily interned. For the most part, only string literals are interned
while all other strings are left to their different references and storage
in memory.


Thats what I meant. Only literals are interned. Dynamically created are
never interned unless you explicitly tell so using String.Intern().
 

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

Back
Top