Print string char by char

Hi,
I need to know if it possible, and how to send a string message to the printer and control the print from the keyboard.
I will explain:
A known text should be print by the printer in a way that each key press (spacebar or other key) will command the printer to print the next char.
i.e the text is "Hello World", the first space bar hit will result "H" on the printer paper, the second spacebar hit will result "e" on the printer paper and "He" is the the current string printed... etc.
if you think its possible or if you know how to do it, I will be happy if you share it with me.
Thanks.

If you're interested in this sort of thing, the following may be of help:
A Demonstration: Using the Java� Print Service API
Printing in Java, Part 1: Acquaint yourself with the Java printing model
The Java� Tutorial - I/O: Reading and Writing (but no 'rithmetic)

Similar Messages

  • Putting a string in a char array?

    Is it possible for the following string 'key' to be placed in array without having to manually go through the charAt methods?
    String key = "ABCDEFGH";
    char[] columnNames = {
    key.charAt(0), key.charAt(1), key.charAt(2),key.charAt(3),key.charAt(4),key.charAt(5),key.charAt(6),key.charAt(7),
    };

    I'm still unclear on what you're trying to do. However, I can replace your big charAt() array mess above with the following code:public class ChatAtTest
        public static void main (String[] args)
            String s = "Hello this is not an eleven-char sentence!xxxxxx";
            if (s.length() <= 0 || s.length() % 8 != 0)
                System.err.println("["+s+"] must be a multiple of 8 characters");
                System.exit(8);
            int numRows = s.length()/8;
            char[][] charRows = new char[numRows][];
            for (int i=0; i<numRows; i++)
                String sub = s.substring(i*8, (i*8)+7);
                charRows[i] = sub.toCharArray();
            for (int row = 0; row < charRows.length; row++)
                System.out.print("ROW "+row+"\t : ");
                for (int aChar = 0; aChar<charRows[row].length; aChar++)
                    System.out.print(charRows[row][aChar]+" ");
                System.out.println();
    }you end up with the following output:ROW 0      : H e l l o   t
    ROW 1      : i s   i s   n
    ROW 2      : t   a n   e l
    ROW 3      : v e n - c h a
    ROW 4      :   s e n t e n
    ROW 5      : e ! x x x x x Is that what you're looking for?
    Grant

  • How to parse String into a char?

    Hi all,
    I have a String variable:
    String s="%28";
    However, the actual value I would like to get is indeed a character '%28', i.e. '(' . How can I change this String to the char I want?
    Thanks a lot for your help.

    remove the %
    and use:char c = (char) Integer.parseInt("28", 16);

  • A quick way to count the number of  newlines '/n' in string of 200 chars

    I am trying to establish the number of lines that a string will generate.
    I can do this by counting the number of '/n' in the string. However my brute force method (shown below) is very slow.
    Normally this would not be a problem on a 2800mhz Athlon (Standard) PC this takes < 1 second. However this code resides within a speed critical loop (not shown). The code shown below is a Achilles heal as far as the performance of this speed critical loop goes.
    Can anyone suggest a faster way to count the number of �/n� (new lines) within a text string of around 50- 1000 chars, given that there may be 10 � 100 newline chars. Speed is a very important factor for this part of my program.
    Thanks in advance
    Andrew.
        int lineCount =0;
        String txt = this.getText();
        //loop throught text and count the carridge returns
        for (int i = 0; i < txt.length(); i++)
          char ch = txt.charAt(i);
          if (ch == '\n')
           lineCount ++;
        }//end forMessage was edited by:
    scottie_uk
    Message was edited by:
    scottie_uk

    Well, here is a C version. On my computer the Java version (reply 9 above) is slightly faster than C. YMMV. For stuff like this a compiler can be hard to beat even with assembler, as you need to do manual loop unrolling and method inlining which turn assembly into a maintenance nightmare.
    // gcc -O6 -fomit-frame-pointer -funroll-loops -finline -o newlines.exe newlines.c
    #include <stdio.h>
    #include <string.h>
    #if defined(__GNUC__) || defined(__unix__)
    #include <time.h>
    #include <sys/time.h>
    #else
    #include <windows.h>
    #endif
    #if defined(__GNUC__) || defined(__unix__)
    typedef struct timeval TIMESTAMP;
    void currentTime(struct timeval *time)
        gettimeofday(time, NULL);
    int milliseconds(struct timeval *start, struct timeval *end)
        int usec = (end->tv_sec - start->tv_sec) * 1000000 +
         end->tv_usec - start->tv_usec;
        return (usec + 500) / 1000;
    #else
    typedef FILETIME TIMESTAMP;
    void currentTime(FILETIME *time)
        GetSystemTimeAsFileTime(time);
    int milliseconds(FILETIME *start, FILETIME *end)
        int usec = (end->dwHighDateTime - start->dwHighDateTime) * 1000000L +
         end->dwLowDateTime - start->dwLowDateTime;
        return (usec + 500) / 1000;
    #endif
    static int count(register char *txt)
        register int count = 0;
        register int c;
        while (c = *txt++)
         if (c == '\n')
             count++;
        return count;
    static void doit(char *str)
        TIMESTAMP start, end;
        long time;
        register int n;
        int total = 0;
        currentTime(&start);
        for (n = 0; n < 1000000; n++)
         total += count(str);
        currentTime(&end);
        time = milliseconds(&start, &end);
        total *= 4;
        printf("time %ld, total %d\n", time, total);
        fflush(stdout);
    int main(int argc, char **argv)
        char buf[1024];
        int n;
        for (n = 0; n < 256 / 4; n++)
         strcat(buf, "abc\n");
        for (n = 0; n < 5; n++)
         doit(buf);
    }

  • How to improve the speed of creating multiple strings from a char[]?

    Hi,
    I have a char[] and I want to create multiple Strings from the contents of this char[] at various offsets and of various lengths, without having to reallocate memory (my char[] is several tens of megabytes large). And the following function (from java/lang/String.java) would be perfect apart from the fact that it was designed so that only package-private classes may benefit from the speed improvements it offers:
        // Package private constructor which shares value array for speed.
        String(int offset, int count, char value[]) {
         this.value = value;
         this.offset = offset;
         this.count = count;
        }My first thought was to override the String class. But java.lang.String is final, so no good there. Plus it was a really bad idea to start with.
    My second thought was to make a java.lang.FastString which would then be package private, and could access the string's constructor, create a new string and then return it (thought I was real clever here) but no, apparently you cannot create a class within the package java.lang. Some sort of security issue.
    I am just wondering first if there is an easy way of forcing the compiler to obey me, or forcing it to allow me to access a package private constructer from outside the package. Either that, or some sort of security overrider, somehow.

    My laptop can create and garbage collect 10,000,000 Strings per second from char[] "hello world". That creates about 200 MB of strings per second (char = 2B). Test program below.
    A char[] "tens of megabytes large" shouldn't take too large a fraction of a second to convert to a bunch of Strings. Except, say, if the computer is memory-starved and swapping to disk. What kind of times do you get? Is it at all possible that there is something else slowing things down?
    using (literally) millions of charAt()'s would be
    suicide (code-wise) for me and my program."java -server" gives me 600,000,000 charAt()'s per second (actually more, but I put in some addition to prevent Hotspot from optimizing everything away). Test program below. A million calls would be 1.7 milliseconds. Using char[n] instead of charAt(n) is faster by a factor of less than 2. Are you sure millions of charAt()'s is a huge problem?
    public class t1
        public static void main(String args[])
         char hello[] = "hello world".toCharArray();
         for (int n = 0; n < 10; n++) {
             long start = System.currentTimeMillis();
             for (int m = 0; m < 1000 * 1000; m++) {
              String s1 = new String(hello);
              String s2 = new String(hello);
              String s3 = new String(hello);
              String s4 = new String(hello);
              String s5 = new String(hello);
             long end = System.currentTimeMillis();
             System.out.println("time " + (end - start) + " ms");
    public class t2
        static int global;
        public static void main(String args[])
         String hello = "hello world";
         for (int n = 0; n < 10; n++) {
             long start = System.currentTimeMillis();
             for (int m = 0; m < 10 * 1000 * 1000; m++) {
              global +=
                  hello.charAt(0) + hello.charAt(1) + hello.charAt(2) +
                  hello.charAt(3) + hello.charAt(4) + hello.charAt(5) +
                  hello.charAt(6) + hello.charAt(7) + hello.charAt(8) +
                  hello.charAt(9);
              global +=
                  hello.charAt(0) + hello.charAt(1) + hello.charAt(2) +
                  hello.charAt(3) + hello.charAt(4) + hello.charAt(5) +
                  hello.charAt(6) + hello.charAt(7) + hello.charAt(8) +
                  hello.charAt(9);
             long end = System.currentTimeMillis();
             System.out.println("time " + (end - start) + " ms");
    }

  • Can we create a structure with string type not char??

    Hi All
    Can we create a structure with type STRING not as a CHAR type??
    Please its urgent.
    Regards
    Deepanker

    HI,
    Yes, you can string instead of CHAR.
    Please follow the steps below :
    SE11 --> Table name --> Create Button --> And input the short description and necessary Delivery and Maintenance fields --> Select Fields tab --> Input some name on field --> And Click on Predefined button --> Press F4 on Data type column --> a Pop window will be displayed --> Select String from that.
    Thanks,
    Sriram Ponna.

  • Conver String object into char

    Hi friends,
    I don't know how convert the String object into char(Primitive data type), using wrapper class?
    Kindly let me know.

    Have a look in the String API documentation for a method that returns an array of char.
    (It's not really what most people would describe as a wrapper class: that's more like converting a single char into an instance of Character.)

  • Deprecated conversion from string constant to 'char*'

    Hi all
    I am working with strings and i cant figure out why the following
    warning appears at time of build.
    warning: deprecated conversion from string constant to 'char*'
    It appears for the line
    char *myName = "Apple.txt";
    Is there anyone who can help me?
    Help is welcome.
    Thanks in advance.

    Any reason why you aren't using NSString in place of char?
    char *myName = "Apple.txt";
    NSString *myName = @"Apple.txt";

  • Load String into CharArray and then Print String in Reverse?

    Hey, what would the code be to:
    1. Ask user for name. (scanner)
    2. Load his name into a CharArray.
    3. Then print out his name backwards.
    thanks a lot!

    dforevergold has a head on his neck. So, I don't understand people saying about assignments etc... If he needs help and we can help then we must help.
    Here's the code (but don't forget about comments!):
    import java.util.Scanner;
    public class Just {
         public static void main(String[] args) {
              // a scanner to get user's input
              Scanner scan = new Scanner(System.in);
              // Scanner.nextLine() returns the entered line
              String name = scan.nextLine();
              // toCharArray() converts a 'String' object to a 'char[]' object
              char[] ch = name.toCharArray();
              // next FOR-loop goes from the last element in the array to the first one and prints them onscreen
              for (int i = ch.length - 1; i >= 0; --i) System.out.print(ch);
    I hope it helps you!
    Yours Sincerely,
    Nikaustr

  • Nontyp template argument, char[] vs char*

    Hi
    I just tried to compile this example
    #include <iostream>
    using namespace std;
    template <const char *str>
    struct xyz
      const char *p;
      xyz() : p(str) { }
      void print() { cout << str << endl; }
    char Comeau[] = "Comeau C++";
    int main()
      xyz<Comeau> x; // Now ok
      x.print();
    }(slightly modified to be standalone, from here:
    http://www.comeaucomputing.com/techtalk/templates/)
    It compiles and runs OK with GCC 4.0.2. With
    CC: Sun Ceres C++ 5.10 SunOS_sparc 2009/03/06
    I get
    CC -library=stlport4 +w2 bad_template.cpp -o bad_template
    "bad_template.cpp", line 17: Error: Template parameter str requires an expression of type const char*.
    1 Error(s) detected.
    Is there a workaround for this?
    Paul

    It's a compiler bug. Please file a bug report on the C++ compiler at [http://bugs.sun.com]
    A possible workaround is to declare Comeau as extern const. (Plain const would make it static.):
    extern const char Comeau[] = "Comeau C++"; You would not be able to modify the array, of course.

  • How to use standard IO as char by char device ?

    Hi,
    I'm looking for an solution to use console entry as character by character device...
    The default System.in can only be ready after the "enter" key stroke.
    Is somebody know how to authorize reading every time a key is stroke ?
    I wish to control user entry to help with shortcut ( as tab key under linux )
    Thanks

    System.in is a 'char-by-char' stream, however, most shells/os's only deliver the keyboard input to a program when the user hits enter. This makes sense if you want the input to already have backspaces and the like dealt with.
    You will have to convince your shell/os to operate in 'raw' mode. In unix you can do that with 'stty raw'. Other os's will be different.

  • Diff between Compounded chara & Refrence chara

    Hi
    diff between Compounded chara & Refrence chara
    Thanks
    Kawal

    Hi,
    You go for compounding when you are unable to define the info objects uniquely.
    But you'll go for reference characteristics where in you have a scenario like several InfoObjects should have same technical properties and master data. In this case you'll create a Reference characteristic having the required operational semantics and then you'll create required InfoObjects basing on this reference characteristic.
    For detailed discussion on this please go through this link:
    http://help.sap.com/saphelp_nw70/helpdata/en/ff/f470375fbf307ee10000009b38f8cf/content.htm
    Regards,
    Habeeb
    Assign points if helpful...:)

  • Performance question when compare date with date or char with char

    Hello from Germany (Frankfurt) !
    I am working on Oracle 9.2.0.8.0
    and have to solve following problem:
    Comparison of a date and char fields.
    Now two ways to do it.
    Either I compare char with char and convert date to char,
    or I compare date with date and convert char to date.
    Now the performace question. Which operation takes more effort for the database?
    So why not to try and to see the results?
    First create table:
    CREATE TABLE TEST (
    char_date VARCHAR2(8),
    real_date DATE
    NOLOGGING;
    Then insert 1.000.000 rows
    BEGIN
    for x in 1..1000000
    loop
    insert into test (char_date, real_date) VALUES('19990101', TO_DATE('2006.01.01', 'YYYY.MM.DD'));
    end loop;
    COMMIT;
    END;
    Collect statistics
    EXEC dbms_stats.gather_table_stats('TESTER', 'TEST');
    Now run some selects for date to char conversion:
    Elapsed: 00:00:00.00
    SQL> select * from test t where TO_DATE(char_date, 'YYYYMMDD') > real_date;
    no rows selected
    Elapsed: 00:00:03.02
    SQL> select * from test t where TO_DATE(char_date, 'YYYYMMDD') > real_date;
    no rows selected
    And some selects for char to date conversion:
    Elapsed: 00:00:03.02
    SQL> select * from test t where char_date > TO_CHAR(real_date, 'YYYYMMDD');
    no rows selected
    Elapsed: 00:00:02.05
    SQL> select * from test t where char_date > TO_CHAR(real_date, 'YYYYMMDD');
    no rows selected
    Elapsed: 00:00:02.05
    SQL>
    As you see when I compare char with char and convert date to char it seems to be faster (almost 1 second)
    Is the test correct?
    I still not sure, what gets better performance...
    Any idea?
    Thanks!

    Depends on whether you want the right results or not.
    Why don't you run the following two queries and see if the difference in results tells you anything?:
    with t as (select to_date('01/02/2007', 'dd/mm/yyyy') date_col from dual
               union all
               select to_date('02/02/2007', 'dd/mm/yyyy') from dual
               union all
               select to_date('03/02/2007', 'dd/mm/yyyy') from dual
               union all
               select to_date('03/03/2006', 'dd/mm/yyyy') from dual)
    select *
    from   t
    where  date_col < to_date('04/03/2006', 'dd/mm/yyyy');
    with t as (select to_date('01/02/2007', 'dd/mm/yyyy') date_col from dual
               union all
               select to_date('02/02/2007', 'dd/mm/yyyy') from dual
               union all
               select to_date('03/02/2007', 'dd/mm/yyyy') from dual
               union all
               select to_date('03/03/2006', 'dd/mm/yyyy') from dual)
    select *
    from   t
    where  to_char(date_col) < '04/03/2006';

  • Use of formatting when printing strings

    I would like to know how to print a string that is italicized. I am open to ideas involving complicated methods .. good to learn something new.

    831334 wrote:
    Well I am a graduate student in Computer Science currently building from scratch a database program as part of my school database class I am taking this semester. I have taken undergraduate courses in Java covering simple types, and data structures; at the graduate level algorithm analysis covering topics such as Fourier Transforms. I am also engaged in improving my C programming skills and learning Python to boot.Well that's nice for you, but I doubt many will be impressed here.
    When I originally posted I thought I would receive an answer to my question regardless where I posted; perhaps this forum would be more active and relevant for my question. Now that my resume is out there including a background in electrical engineering, should I hit Google or can I get an answer to my question?Now I know that one shouldn't expect much eloquence from a computer scientist, but your original question of "How can I print Strings in italics" wasn't exceptionally well thought out. Or was it news to you that Java is capable of outputting Strings in more ways than outputting to a standard console?
    If not the current adage is: "Its easy, just Google it" will suffice and follows the wade through data overload but oh well.We gave you plenty of answers already, do we need to hold a lecture for you to understand them?

  • Firefox is crashing repeatedly upon opening. There are a 3 different signature reasons, but this is the most common: Signature: memmove | nsCacheMetaData::SetElement(char const*, char const*)

    This started yesterday afternoon, where Firefox crashes immediately upon opening. I do have a lot of tabs that open upon start (this is done with the "Morning Coffee" add-on), but this has never been a problem before. This morning, I had 5 separate crashes, all in a row:
    Signature: memmove | nsCacheMetaData::SetElement(char const*, char const*)
    Signature: PR_EnterMonitor
    Signature: _PR_MD_PR_POLL
    Signature: memmove | nsCacheMetaData::SetElement(char const*, char const*)
    Signature: memmove | nsCacheMetaData::SetElement(char const*, char const*)
    However, I WAS able to open up Firefox and get it to run without crashing when I did so with no tabs automatically opening.
    Can someone help?
    Thanks !!!!

    You can post the ID of the crash report instead of the full crash report.
    *bp-daecec88-b15e-474b-8ebc-4af9b2141118
    This is an out-of-memory crash where all available memory is used up.
    You can try to disable hardware acceleration in Firefox.
    *Tools > Options > Advanced > General > Browsing: "Use hardware acceleration when available"
    You need to close and restart Firefox after toggling this setting.
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes
    *https://support.mozilla.org/kb/upgrade-graphics-drivers-use-hardware-acceleration
    Do a malware check with several malware scanning programs on the Windows computer.
    Please scan with all programs because each program detects different malware.
    All these programs have free versions.
    Make sure that you update each program to get the latest version of their databases before doing a scan.
    *Malwarebytes' Anti-Malware:<br>http://www.malwarebytes.org/mbam.php
    *AdwCleaner:<br>http://www.bleepingcomputer.com/download/adwcleaner/<br>http://www.softpedia.com/get/Antivirus/Removal-Tools/AdwCleaner.shtml
    *SuperAntispyware:<br>http://www.superantispyware.com/
    *Microsoft Safety Scanner:<br>http://www.microsoft.com/security/scanner/en-us/default.aspx
    *Windows Defender:<br>http://windows.microsoft.com/en-us/windows/using-defender
    *Spybot Search & Destroy:<br>http://www.safer-networking.org/en/index.html
    *Kasperky Free Security Scan:<br>http://www.kaspersky.com/security-scan
    You can also do a check for a rootkit infection with TDSSKiller.
    *Anti-rootkit utility TDSSKiller:<br>http://support.kaspersky.com/5350?el=88446
    See also:
    *"Spyware on Windows": http://kb.mozillazine.org/Popups_not_blocked
    *https://support.mozilla.org/kb/troubleshoot-firefox-issues-caused-malware

  • Print string array

    Hi
    for printing numbers, I would do this:
    for (int x=0; x<=myArray; x++)
    System.out.prin(x);
    But How would I do for printing String values I have read in to a string array?
    I have read in som names to a string array and can print them by:
    System.out.print(myarray[0] + myArray[2]);
    This would print index 0 and 2 in the array. But this is not so good if you have an index large as 100 for example. So how would i go thru the String array and print out the variables?
    Martin

    dream77 wrote:
    case 2: // Print out the list
                        for (int x=0;x<arrNames.length; x++)
                             if (x < nameCount)
                             System.out.print(arrNames[x]);
    1) ALWAYS enclose for loop and if statements in curly braces, even if it's only one statement. So don't do either of these:
    if (fubar ==3)
        doThis();
    // and
    for (int snafu = 0; snafu < myLength; snafu++)
        doThat();instead write:
    if (fubar ==3)
        doThis();
    // and
    for (int snafu = 0; snafu < myLength; snafu++)
        doThat();
    }You'll thank me for this later.
    2) If nameCount is less than arrNames.length always, why use this as the exit condition in your for loop? i.e.,
    for (int x = 0; x < nameCount; x++)
        System.out.print(arrNames[x]);
    }

Maybe you are looking for

  • The iPod cannot be updated. The required disc cannot be found

    I am gettin an annoying message that "the required disc cannot be found" and am not sure how to resolve. The iPod shuffle seems to updat with songs successfully. I also tries restoring for factory settings to perhaps start from scratch. I also tunred

  • Using a "fopen" call in a DLL made with MatLab for Labview

    Dear Sirs: My name is Juan Crespo and I write you from Spain. I answer if you could help me with a Labview problem. This is the problem. I want to write a DLL for being used in labview, and i want to use matlab for write this DLL. I have been searchi

  • Use a second instance of Python

    Hi.. I hope that what i'll write won't be silly.. I need to run  a program that require a python interpreter with support for unicode UCS4. The python interpreter that is release with archlinux has support for UCS2 instead. I noticed a bug ticket whe

  • "Large" or "Full" "NTSC" or "PAL"

    I recently shot about 3 hours worth of digital video on a Panasonic DVX100B. I am going to cut it down to be a 20 minute promotional video and it will be played on a very big screen in a theater. Here's a link to the best picture I could find of the

  • Restricting a user for KM repository

    Hi All i have created a file repository.Is it possible to set the permission ,so that one user cant access that repository but another user can access the repository. I have tried with setting the details-properties-permissions . Then also every user