?
Solved

How to print a custom character without GUI?

Posted on 2004-11-12
24
Medium Priority
?
252 Views
Last Modified: 2013-12-03
Hello,
I need to print an '@' symbol with an underscore below it.  
I know this can easily be done using a GUI, but I need to send it to the command prompt and a text file if possible.  I thought there might be a way to do this using Unicode characters, but I am unable to figure it out.
0
Comment
Question by:JediPimp
  • 10
  • 9
  • 3
  • +1
24 Comments
 
LVL 13

Expert Comment

by:petmagdy
ID: 12569410
write its hexadecimal correspondent from those table:
http://www.i18nguy.com/markup/ncrs.html
0
 
LVL 1

Author Comment

by:JediPimp
ID: 12569479
petmagdy,
that page seems to just talk about using the characters with HTML, I need to do it in Java.
0
 
LVL 1

Author Comment

by:JediPimp
ID: 12570899
Increased points from 150 to 250.  Anyone know how to do what I need?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Expert Comment

by:pjcrooks2000
ID: 12571313
Why not store the characters as a string variable

e.g.

String Str = "@";

Then print the string out

System.out.println(Str);

Hope this helps

pjcrooks2000
0
 
LVL 13

Accepted Solution

by:
petmagdy earned 1000 total points
ID: 12571523

I tried to get the charater u want i didn't find it on:
http://www.unicode.org
but u can print all unicode characters on a file like this:

      */  
        String str = "";
        char c = '\u0000';
        while(c <=  '\uFEFF' )
        {
            str+=String.valueOf(c) + " ";
               c++;
        }
        System.out.println(str);
//        OutputStreamWriter out = new OutputStreamWriter(new ByteArrayOutputStream());
//        System.out.println(out.getEncoding());
        try
        {
            File fileToWrite = new File( "c:\\characters.txt" );
            FileOutputStream outfile = new FileOutputStream(fileToWrite);
            OutputStreamWriter out = new OutputStreamWriter(outfile, "UTF8");
            System.out.println(out.getEncoding());
            out.write(str);
            out.close();
        }
        catch(Exception ex)
        {
           
        }

0
 
LVL 30

Expert Comment

by:Mayank S
ID: 12574519
>> String Str = "@";
>> System.out.println(Str);

Same as doing System.out.println ( "@" ) ; but it won't print the under-score below it ;-)

Try petmagdy's approach - see if you find that character.
0
 
LVL 8

Expert Comment

by:pjcrooks2000
ID: 12574537
Yes mayankeagle

I realised that after I typed it :)

Just wondering if there is a way to underline text in Java and print this to a console window!  Hmmmm
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 12577180
Should be possible if you can find that character in the list.
0
 
LVL 1

Author Comment

by:JediPimp
ID: 12579629
I took a look at the unicode web page again and found this in the faq:
http://www.unicode.org/faq/char_combmark.html#12

It talks about how you can combine letters, but it doesn't say how it can be done in java.

The two characters that need to be combined would be U+0040 (the at symbol) and U+005F (the underscore).

I looked through the list, but i didn't see the character that i needed.
0
 
LVL 13

Expert Comment

by:petmagdy
ID: 12579718
ok i am very close:

       char c = '\u0040'; // the @ character
        str+=String.valueOf(c);
        c = '\u0332'; //combining low line character
        str+=String.valueOf(c);
        System.out.println(str);
        try
            {
              File fileToWrite = new File( "f:\\characters.txt" );
              FileOutputStream outfile = new FileOutputStream(fileToWrite);
              OutputStreamWriter out = new OutputStreamWriter(outfile, "UTF16");
            System.out.println(out.getEncoding());
            out.write(str);
            out.close();
            }
        catch(Exception ex)
            {
              
            }

combining means append to ur character one of the combining letters, if LOW line dosn't work for u try one of the other combining letters
0
 
LVL 1

Author Comment

by:JediPimp
ID: 12580872
petmagdy,
Are you able to see it as one character, because I am unable to.  The underscore doesn't appear when using the Lucida Sans Unicode font or the Arial Unicode MS font.
0
 
LVL 13

Expert Comment

by:petmagdy
ID: 12581237
yes, open the file generated u will find that it contains only one charater @ with some underline
0
 
LVL 13

Expert Comment

by:petmagdy
ID: 12581238
just try to open the file with notepad
0
 
LVL 1

Author Comment

by:JediPimp
ID: 12581392
I did try it with notepad, with each of the four encodings provided, UTF16 doesn't seem to be one of them though.  I also tried viewing it using edit from the dos prompt, that didn't work either.  are you able to copy and paste the char here, or possibly e-mail it, I might be able to just paste it into my program and get it to print.
0
 
LVL 13

Expert Comment

by:petmagdy
ID: 12581399
Here is it, also u can try in my code UTF8 instead of UTF16, it try it gave thr same result

@&#818;
0
 
LVL 13

Expert Comment

by:petmagdy
ID: 12581405
oops the site converted to wha u see!

what is ur OS and what JDK version r u using?
Mine is XP and JDK 1.4.2
0
 
LVL 1

Author Comment

by:JediPimp
ID: 12583821
I am using the same. Win XP and JDK 1.4.2.
0
 
LVL 13

Expert Comment

by:petmagdy
ID: 12584858
ok, then u should be able to view the character in file, I can send u the character, please provide means of sending u the file contents
0
 
LVL 1

Author Comment

by:JediPimp
ID: 12586326
ok, please send it to dr_nebuchadnezzar03 at yahoo.com
0
 
LVL 13

Expert Comment

by:petmagdy
ID: 12586362
ok done
0
 
LVL 1

Author Comment

by:JediPimp
ID: 12586425
I still see the same thing as before, what font are you using in notepad to view it?
0
 
LVL 13

Expert Comment

by:petmagdy
ID: 12586441
Lucida Console
0
 
LVL 1

Author Comment

by:JediPimp
ID: 12586510
It still doesn't work, using Lucida Console with any of the encoding formats provided by notepad, so I guess it is probably a problem with my computer.  Thanks for your help.

JediPimp
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 12592254
Moderators don't like posting e-mail IDs on question-pages.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month17 days, 6 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question