Putting a null character in a String?

Hi,
I need to send a null character through a nio channel. Specifically, it needs to be decoded from a String into a byte array. Can I append a null character to a String so that getBytes() method will return it? Thanks,
ranko

Thanks, I tried that but it doesn't work. I also
tried appending '\0' and an uninitialized character
which should by default have a value of a null
character. I tried creating a String out of a char
array that has one element containing a null character
but that did not work either. I guess that since null
characters end the String, you cannot actually add
them to the body of the String. Or is there a way?FYI, strings aren't null-terminated in Java.

Similar Messages

  • Problem to put a special character in a string

    I read a file that contains some special characters.
    One of them has a hexadecimal value '8D'.
    When i put this in a string or a char, it give me '?'.
    If i read my file int by int, this char value is 65533
    How can I do to display this character as it must be? How can i transform it to put it in a string?

    8D is "reverse linefeed" in unicode: http://www.unicode.org/charts/PDF/U0080.pdf
    Obviously it's something else in your system's character encoding. What do you think you should get from 8D?

  • JCO.Server appends null character to string

    I am a complete SAP and JCO newbie so I'll try making as much since as I can, given the fact that I'm not familiar with SAP terminology and technology. I've been lent as a developer to another group which needs a legacy application rewritten. The application processes a RFC and decrypts the RFC encrypted payload and returns it along with a status code.
    I have made progress - I'm able to register my server with the SAP runtime and using the SAP GUI application and the help of a SAP developer, I'm able to make an RFC call to my application. I'm able to read the parameters sent from SAP and write parameters back.
    The problem is that one of the parameters I'm writing back (java.lang.String) appears to have and extra character on SAP side. On the GUI it appears as a '#' (pound) sign. The SAP developer told me the string is terminated with a null character which I know is a C/C++ thing but not a Java thing. I don't think it is a Unicode issue. The Java server is not running in Unicode mode and any attempt to set the jco.server.unicode property (I may have forgotten the exact name) to a value of 1 causes the RFC to fail.
    I think the issue is likely to be the manner in which I defined the function parameters or the manner in which I write them. The following are code snippets:
    Defining the function:
    JCO.MetaData metadata = new JCO.MetaData(Constants.FUNCTION_DECRYPT);
    metadata.addInfo(Constants.PARAMETER_SCHEME,      JCO.TYPE_INT,    255,   0,  0, JCO.IMPORT_PARAMETER, null);
    metadata.addInfo(Constants.PARAMETER_ENCRYPTED,   JCO.TYPE_STRING, 255,   0,  0, JCO.IMPORT_PARAMETER, null);
    metadata.addInfo(Constants.PARAMETER_DECRYPTED,   JCO.TYPE_STRING, 255,   0,  0, JCO.EXPORT_PARAMETER, null);
    metadata.addInfo(Constants.PARAMETER_RETURN_CODE, JCO.TYPE_INT,    255,   0,  0, JCO.EXPORT_PARAMETER, null);
    Server request handling code:
    protected void handleRequest(JCO.Function function)
                    // Obtaining import/export parameter lists.
                    JCO.ParameterList input  = function.getImportParameterList();
                    JCO.ParameterList output = function.getExportParameterList();
                    // Getting scheme and encrypted text parameters.
                    int scheme       = input.getInt(Constants.PARAMETER_SCHEME);
                    String encrypted = input.getString(Constants.PARAMETER_ENCRYPTED);
                    // Decoding base 64 string.
                    byte[] bytes = Base64.decode(encrypted);
                    // Obtaining cipher by scheme and decrypting the text.
                    AppCipher cipher = ApplicationConfiguration.getDecryptor(scheme);
                    if(cipher == null)
                                    logger.error("Unable to get cipher due to an unknown encryption scheme: " + scheme);
                    else
                                    byte[] decrypted = cipher.decrypt(bytes);
                                    String plainText = new String(decrypted);
                                    // Setting decrypted value information and return code.
                                    output.setValue(plainText, Constants.PARAMETER_DECRYPTED);
                                    output.setValue(Constants.RETURN_CODE_SUCCESS, Constants.PARAMETER_RETURN_CODE);

    I seem to have made progress. If I define the parameter type as JCO.TYPE_CHAR instead of JCO.TYPE_STRING, it works:
    metadata.addInfo(Constants.PARAMETER_DECRYPTED,   JCO.TYPE_CHAR,   255,   0,  0, JCO.EXPORT_PARAMETER, null);
    That is the only change I made. I'm still setting the parameter value as java.lang.String. I hope this won't cause issues elsewhere. I was also able to change the field definition and set it as a byte array. However, that had the problem of having to define the exact length of the byte array in the field metadata otherwise the remaining bytes would appear as null bytes on SAP side.

  • Save null character to excel

    Because MS Excel cells expect null terminated strings, I'm losing data when writing to Excel using active X from LabVIEW. What I am doing is typecasting an array to a string, and storing that string in a single Excel cell. But, if that string has a null character, all data after it is lost. Has anyone overcome this, and if so, how? The reason I want to do this is because my Excel spreadsheet is formatted in the following way
    run1, set1, graph1 array, graph 2 array...graph10array
    run 1, set 2, graph1 array, graph 2 array...graph10array
    run2, set 1, graph1 array, graph 2 array...graph10array
    run n, set n,graph1 array, graph 2 array...graph10array 
    This allows me to search for "run n, set n" and get all the corresponding graph data very easily. Also, unfortunately, using a database is not exactly an option .
    CLA, LabVIEW Versions 2010-2013
    Solved!
    Go to Solution.

    Matt,
    Thanks for your response. The first two are customer driven. Their old format was in a DB and they want to keep that format, but move to excel so they can access other data visually from within Excel. If I was to put the graph stuff in a separate file, i'd then have to map to other files, check to make sure the files are there, etc.
    Encoding and reencoding strings crossed my mind. However, this could potentionally cause "unencoding" of something I don't want to be unencoded. For example, let's say I replace all null characters with a, but then there is an a in the typecasted string which I don't want replaced. It will be replaced anyways. Is there a way around this? I'm thinking maybe do something like replace a null character with the ascii characters NULL. Then use a regex to search and replace. 
    The last one would work and I may just map the data to columns on a different sheet and write all the points.
    Matt W wrote:
    Here's some ideas
    Option1: Don't use excel use tdms instead, combine run and set into the group names, and put the graph arrays into channels, this should be much faster, and easier to deal with 
    Option2: Is there a reason a self contained database wouldn't work. Like the SQLite API for LabVIEW
    Option3: Reencode your strings so they don't contain \0, then unencode them when you read them.
    Option4: Change your format (each sample from the graphs goes into it's on cell)
    CLA, LabVIEW Versions 2010-2013

  • Match Pattern does not function properly when searching for a null character

    I'm using Match Pattern to extract a null terminated string from a response I'm getting from a device on a serial port. The VI is attached and below is a screenshot of the block diagram.
    It works just fine with index set to 0, 1, or 2. When index is 3, I get the output shown below.
    Why is Match Pattern not finding the null character?
    Thanks!
    Solved!
    Go to Solution.
    Attachments:
    Grab Nullterm String.vi ‏15 KB

    I'm a dope, need to remove the wire from the Offset control to the Match Pattern control.
    DUH!

  • How to get a set of character within a string?

    Hi,
    I need to cut a set of character within a string. I have tried everthing but I need help.
    Example.
    Database Version 11.2.0.3
    create table tst_string (message varchar2(600));
    insert into tst_string values ('ANR0166I Inventory file expiration finished processing for node OSOGBO, filespace OSOGBO\SystemState, copygroup BACKUP and object type GROUP BASE with processing statistics: examined 43, deleted 43, retrying 0, and failed 0. (SESSION: 1506, PROCESS: 2)');
    insert into  tst_string values ('ANE4175I Starting Full VM restore of VMware Virtual Machine ''mfujiwara'' target node name=''VC1_DC1'', data mover node name=''VC1_DC1_DM3''  (SESSION: 3780)');
    commit;
    select * from tst_string;
    MESSAGE
    ANR0166I Inventory file expiration finished processing for node OSOGBO, filespace OSOGBO\SystemState, copygroup BACKUP and object type GROUP BASE with processing statistics: examined 43, deleted 43, retrying 0, and failed 0. (SESSION: 1506, PROCESS: 2)
    ANE4175I Starting Full VM restore of VMware Virtual Machine 'mfujiwara' target node name='VC1_DC1', data mover node name='VC1_DC1_DM3'  (SESSION: 3780)
    ## I want get
    # From first line following values:
    node OSOGBO
    filespace OSOGBO\SystemState
    examined 43
    deleted 43
    retrying 0
    failed 0
    # From second line
    mfujiwara
    VC1_DC1
    VC1_DC1_DM3Any help can be useful...
    Thanks in advance.

    Hi Frank,
    It looks like message can be seen as delimited lsit of sub-messages, where a number of different characters (perhaps ',' amd ':') may serve as delimiters. Each sub-message may or consist (entirely or in part) of something you want to display.Yes. In my first case where is "ANR0166I" I want get the characteres before "," (e.g "OSOGBO," I want get "OSOGBO") excluding "(SESSION: 1506, PROCESS: 2)"
    Would a user-define PL/SQL function be okay for you?Yes.. no problem.
    I'm not good with shell script, but will try show what I want using SHELL commands:
    See this example:
    ### I create a file named "tst_string"
    $ vi tst_string
    ANR0166I Inventory file expiration finished processing for node OSOGBO, filespace OSOGBO\SystemState\NULL\System State\SystemState, copygroup BACKUP and object type GROUP BASE with processing statistics: examined 43, deleted 43, retrying 0, and failed 0. (SESSION: 1506, PROCESS: 2)
    ## So I used a function sed to get my desired values. The command bellow is poor, but My point is the result.
    $ cat tst_string | sed 's/ANR0166I.*node //g' | sed 's/, filespace//g' | sed 's/, copygroup BACKUP and object type GROUP BASE with processing statistics: //g' | sed 's/. (SESSION.*//g' | sed 's/, deleted//g' | sed 's/, retrying//g' | sed 's/, and failed//g'
    OSOGBO OSOGBO\SystemState\NULL\System State\SystemState 43 43 0 0The result was:
    NODE     FILESPACE                              Examined     Deleted     Retrying        Failed      
    OSOGBO      OSOGBO\SystemState\NULL\System State\SystemState     43           43      0           0I will go check the links wich you mentioned.
    Thanks

  • The first character in a string

    I need to return the first character of a string, convert it to an integer, and compare it with another integer to see if they're the same. Sounds simple, even for me, but it won't work!!!
    // First question >
    Object userValue1 = JOptionPane.showInputDialog("Blah Blah Blah", JOptionPane.PLAIN_MESSAGE, null, options1, options1[0]);
    Variables.placeholder = (int) userValue1.charAt(0);This is the error I get
    C:\Documents and Settings\imholt\My Documents\OOPAttempt\21_Questions\Engine.java:170: cannot resolve symbol
    symbol : method charAt (int)
    location: class java.lang.Object
              Variables.placeholder = (int) userValue1.charAt(0);
    ^
    1 error
    I have a sneaky suspicion that once I find out what the problem was, I will ask myself why I didn't see it before...

    Try this
    Object userValue1 = JOptionPane.showInputDialog("Blah Blah Blah", JOptionPane.PLAIN_MESSAGE, null, options1, options1[0]);
    String str = userValue1.toString();
    Variables.placeholder = (int) str.charAt(0);

  • Inserting the "enter" character in a String

    Hi,
    I would like to insert a "enter" character in a String to create a new line.
    something like this
    String test = "teste" + char(10) + "teste";
    Thanks in advanced
    Ricardo

    Are you trying to do this in an email? You didn't mention that. If your email encoding doesn't support new lines (the most simple encoding doesn't) you can't send them. I don't know why you'd get those results though, unless you actually put "\\n\\r" in the Java program.
    Anyway, it's not "my solution" it's just a fact. '\n' is the newline character and '\r' is the carriage return character.

  • Non-Alphanumeric Character in a String

    I understand if we have a non-alphanumeric character in a String, we have to put a backward slash in front of that character. For example, we have to put a backward slach in front of a "backward slash". Eg. we do \\ to put a backward slash in a String.
    What about a dot (.) or a dash (-)? Do we have to do the same thing?

    No, it's only for control characters like "newline", characters with special meaning in strings i.e. " and \ and any character that can't be represented in the character encoding of your java source file.

  • Print a null character

    Okay, so I open a socket and connect to a networked machine that accepts strings as commands. Commands are terminated by the null character '\0'. I know this works as I've done it in Python with no problems. Right now all I'm trying to do is write an ascii char "0" followed by a null. My machine isn't responding and I'm pretty sure its because Java is ignoring my '\0' and just writing the characters preceding it.
       public void connect() throws IOException{
            System.out.println("Trying to connect...\n");
            //connect to roobt
            Socket outsock = new Socket("13.62.154.243", 15223);
            Socket insock = new Socket("13.62.154.243",15224);
            //setup reading/writing.
            PrintWriter out = new PrintWriter(outsock.getOutputStream());
            BufferedReader in = new BufferedReader(new InputStreamReader(insock.getInputStream()));
            String r = in.readLine();
            System.out.println("Received: " + r + "\n");
            //inform robot that connection is closing
            out.print("0\0");
            //close sockets
            outsock.close();
            insock.close();
        }Am I wrong? Is there a way to force the null character to be written?
    And as an aside, is there a way to read lines terminated by a null as opposed to a newline \n or carriage return \r? I can modify the code on the machine to respond with lines terminated by \n's, but I'd rather not have to redo it all. I wrote the code for my machine to function with a Python socket script, and now I'm attempting to rewrite this into Java.

    http://java.sun.com/j2se/1.5.0/docs/api/java/util/Scan
    ner.html
    Use the null character as the delimiter.Okay, I see how this could be useful, except I don't have a string yet. A have a BuffereReader that I need to make into a string. Once its a string, then I could use the scanner. Right? So, I still have a problem.

  • Count a character within a string

    Give a string, what function can I use to count how many a particular character in the string. For example:
    "abc;def;ghi;xyz"
    I want to find out how many ";" in this string.
    Thank you

    And of course, if the researched character is not in the given string, then you'll return null, to return 0, you'll need a NVL.even if it is in the string you might need a nvl in Vamsi Kasina's solution:
    SQL>  select length (';') - length (replace (';', ';')) cnts
      from dual
          CNTS
    1 row selected.Better:
    SQL>  select nvl(length (';'),0) - nvl(length (replace (';', ';')),0) cnts
      from dual
          CNTS
             1

  • Binary Representation of null character

    Is it true that null character is represented by '\u0000'? When I try to convert the above using Character.digit(char, 2), I got the hex value 0xFF. So can I say that the binary representation of a null character is 11111111? Can anybody help me with this? Thank you.

    I managed to store 0x91a3b1f855e62708L in a type long by using the method below provided by dpz from this forum
    public static long hexToLong(String hex) {
    String highOrderDigits = "89abcdef";
    //Only process exactly 16-digit strings.
    if (hex.length() != 16) {     
    throw new IllegalArgumentException("Expect 16-digit hex value");
    boolean overflow = false;
    //Check for most significant digit > 7,
    //which would cause problem for parseLong.
    int highOrderIndex = highOrderDigits.indexOf(hex.charAt(0));
    if (highOrderIndex > -1) {     
    // Clear most-significant bit and set overflow flag.
    overflow = true;
    hex = "" + highOrderIndex + hex.substring(1);
    long result = Long.parseLong(hex, 16);
    if (overflow) {  
    //Manually set most significant bit in result.
    result |= 0x8000000000000000L;
    return result;

  • Testing the last character of a string using .endsWith

    Hi,
    I want to check to see if the last character of a string is '@'.
    I tried if (StringAt.endsWith("a")) {
    but got no results.
    Is this the correct way to do it or is there another way.
    Thanks.
    Adam

    javadocs:
    String's endsWith method takes a string argument.
    endsWith
         public boolean endsWith(String suffix)
              Tests if this string ends with the specified suffix.
              Parameters:
                   suffix - the suffix.
              Returns:
                   true if the character sequence represented by the argument is a suffix of the character sequence
                   represented by this object; false otherwise. Note that the result will be true if the argument is the
                   empty string or is equal to this String object as determined by the equals(Object) method.
              Throws:
                   NullPointerException - if suffix is null.

  • Inserting Null character through C into Oracle

    Hello,
    I am reading data through pro C program from a file which contains null characters.
    I am fetching data into character buffer but when I try to insert the buf into Oracle of table it is inserting all the charaters before that null character and the remaining characters after the null characters will be truncated.
    So kindly help me how to handle null character ion Pro C and insert the entire characters string which contains null characters in Varchar field.
    Thanks,
    Ananth
    null

    Please check the pro C/C++ developers guide.

  • How to count number of occurences of a character  in a string

    I want to get the count of occurences of a character within a string. Is there any function for this or should i go for a PLSQL.
    For example is the sting is "occurences" & if i search for character "c", the answer should be 3.
    Regards,
    Sunil.

    SQL> select length('occurence') - length(replace('occurence','c')) from dual;
    LENGTH('OCCURENCE')-LENGTH(REPLACE('OCCURENCE','C'))
    3

Maybe you are looking for

  • Re: how to enable s-video output in lenovo R61i--- What buttons ???

    What buttons enable S- video on R61  ????

  • QuickTime movie clips won't play in video player

    I have movie clips generated by my camera that are in Quicktime format that are in iTunes and iPhoto (playing in both) but will not sync to the iPad because they are in an "unsupported format" I have a few other QT clips that did sync to the iPad fro

  • FILE SIZES DIFFERENT WHEN UPLOADING

    I'm almost bald from pulling my hair out!!! I have exported photos to my harddrive as jpegs that are less than 1mb but when I try to upload them for an assignment on the school website they are 25 mb??

  • VAT TIN No. of Company

    For entering Company's VAT TIN No., do we need to set Country India as "EU Member" in T.code OY01?? If not, then where do we enter Company's VAT TIN No.? Please Guide Regards Ashwin

  • Unable to do in app purchase

    I can't do any in app purchases anymore. I get an error that the transaction failed and that I should contact support. I did this yesterday, but they seem to ignore me now. First they disabled my account and credit card (after lots of mails and a pho