Get 7-bit ASCII character array from input String. : String ASCII « Data Type « Java






Get 7-bit ASCII character array from input String.

  

/*

 Derby - Class org.apache.derby.iapi.util.PropertyUtil

 Licensed to the Apache Software Foundation (ASF) under one or more
 contributor license agreements.  See the NOTICE file distributed with
 this work for additional information regarding copyright ownership.
 The ASF licenses this file to you under the Apache License, Version 2.0
 (the "License"); you may not use this file except in compliance with
 the License.  You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.

 */

public class Main {



  /**
    Get 7-bit ASCII character array from input String.
    The lower 7 bits of each character in the input string is assumed to be
    the ASCII character value.

     Hexadecimal - Character

     | 00 NUL| 01 SOH| 02 STX| 03 ETX| 04 EOT| 05 ENQ| 06 ACK| 07 BEL|
     | 08 BS | 09 HT | 0A NL | 0B VT | 0C NP | 0D CR | 0E SO | 0F SI |
     | 10 DLE| 11 DC1| 12 DC2| 13 DC3| 14 DC4| 15 NAK| 16 SYN| 17 ETB|
     | 18 CAN| 19 EM | 1A SUB| 1B ESC| 1C FS | 1D GS | 1E RS | 1F US |
     | 20 SP | 21  ! | 22  " | 23  # | 24  $ | 25  % | 26  & | 27  ' |
     | 28  ( | 29  ) | 2A  * | 2B  + | 2C  , | 2D  - | 2E  . | 2F  / |
     | 30  0 | 31  1 | 32  2 | 33  3 | 34  4 | 35  5 | 36  6 | 37  7 |
     | 38  8 | 39  9 | 3A  : | 3B  ; | 3C  < | 3D  = | 3E  > | 3F  ? |
     | 40  @ | 41  A | 42  B | 43  C | 44  D | 45  E | 46  F | 47  G |
     | 48  H | 49  I | 4A  J | 4B  K | 4C  L | 4D  M | 4E  N | 4F  O |
     | 50  P | 51  Q | 52  R | 53  S | 54  T | 55  U | 56  V | 57  W |
     | 58  X | 59  Y | 5A  Z | 5B  [ | 5C  \ | 5D  ] | 5E  ^ | 5F  _ |
     | 60  ` | 61  a | 62  b | 63  c | 64  d | 65  e | 66  f | 67  g |
     | 68  h | 69  i | 6A  j | 6B  k | 6C  l | 6D  m | 6E  n | 6F  o |
     | 70  p | 71  q | 72  r | 73  s | 74  t | 75  u | 76  v | 77  w |
     | 78  x | 79  y | 7A  z | 7B  { | 7C  | | 7D  } | 7E  ~ | 7F DEL|

   */
  public static byte[] getAsciiBytes(String input)
  {
    char[] c = input.toCharArray();
    byte[] b = new byte[c.length];
    for (int i = 0; i < c.length; i++)
      b[i] = (byte)(c[i] & 0x007F);

    return b;
  }


}

   
    
  








Related examples in the same category

1.Checks whether the character is ASCII 7 bit.
2.Checks whether the character is ASCII 7 bit printable.
3.Checks whether the character is ASCII 7 bit control.
4.Checks whether the character is ASCII 7 bit alphabetic.
5.Checks whether the character is ASCII 7 bit alphabetic upper case.
6.Checks whether the character is ASCII 7 bit alphabetic lower case.
7.Checks whether the character is ASCII 7 bit numeric.
8.Checks whether the character is ASCII 7 bit numeric and character.
9.Allow text containing mostly ASCII characters to be decipherable on an ASCII terminal without decoding.
10.Removes control characters (char <= 32) from both ends returning null if the String is empty ("") after the trim or if it is null
11.Removes control characters (char <= 32) from both ends returning an empty String ("") if the String is empty ("") after the trim or if it is null.
12.Test if the character is a digit <digit> ::= '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
13.Test if the current character is a digit <digit> ::= '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
14.Test if the current character is a new line.
15.Test if the current character is a space.
16.Test if the current character is an Alpha character : <alpha> ::= [0x41-0x5A] | [0x61-0x7A]
17.Test if the current character is an Ident character
18.Test if the current character is equal to a specific character.
19.Test if the current string is a digit <digit> ::= '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
20.Removes spaces (char <= 32) from both start and ends of this bytes array
21.Removes spaces (char <= 32) from end of this String with escape, handling null by returning null
22.Removes spaces (char <= 32) from end of this String, handling null by returning null
23.Removes spaces (char <= 32) from end of this array by index, handling null by returning null
24.Removes spaces (char <= 32) from end of this array ny position, handling null by returning null
25.Removes spaces (char <= 32) from end of this array, handling null by returning null
26.Removes spaces (char <= 32) from start of this String, handling null by returning null
27.Removes spaces (char <= 32) from start of this array, handling null by returning null
28.Thansform an array of ASCII bytes to a string. the byte array should contains only values in [0, 127].