HOW can I convert int value char TO String

I am trying to study Java by books, but sometimes it is quite difficult to find answers even to simple questions...
I am writing a program that analyzes a Chinese text in Unicode. What I get from the text is CHAR int value (in decimals), and now I need to find them in another text file (with RegEx). But I can't find a way how to convert an INT value of a char into a String.
Could you help me?
Thank you in advance.

You are confusing matters a bit. A char is a char is a char, no matter
how you represent it. Have a look at this:char a= 'A';
char b= 65;Both a and b have the same value. The representation of that value
can be 'A' or 65 or even (char)('B'-1), because the decimal representation
of 'B' is 66. Note the funny construct (char)(...). This construct casts
the value ... back to the char type. Java performs all non-fraction
arithmetic using four byte integers. The cast transforms it back to
a two byte char type.
Strings are just concatenations of zero or more chars. the charAt(i)
method returns you the i-th char in a string. Have a look:String s= "AB";
char a= 'A';
char b= (char)(a+1);
if (a == s.charAt(0)) System.out.println("yep");
if (b == s.charAt(1)) System.out.println("yep");This piece of code prints "yep" two times. If you want to compare two
Strings instead, you have to do this:String s= "AB";
char a= 'A';
char b= 'B';
String t= ""+a+b;
if (s.equals(t)) System.out.println("yep");Note the 'equals' method instead of the '==' operator. Also note that
string t was constructed using those two chars. The above was a
shorthand of something like this:StringBuffer sb= new StringBuffer("");
sb.append(a);
sb.append(b);
String t= sb.toString();This is all handled by the compiler, for now, you can simply use the '+'
operator if you want to append a char to a string. Note that it is not
very efficient, but it'll do for now.
Does this get your started?
kind regards,
Jos

Similar Messages

  • Can u tell me how to convert int value in to string

    hi to all, can u tell me how to convert int value in to string.

    hi to all, can u tell me how to convert int value in
    to string.Even this way:
    int number = 155;
    String mystring = ""+155;
    [\code]                                                                                                                                                                                                                                                                                               

  • How can I convert  an ArrayList to a String[]

    Hi,
    How can I convert an ArrayList (only with strings) to a String[] ?
    I've tried this :
         public static String listToString(List l) {
              StringBuffer sb = new StringBuffer();
              Iterator iter = l.iterator();
              while (iter.hasNext()) {
                   sb.append(iter.next().toString());
                   if (iter.hasNext()) {
                        sb.append(',');
              return sb.toString();
    But what I get is an array of xxxxx@435634 (for example).
    Thanks a lot !

    Strings are Objects but not all Objects are Strings and at least one of the elements in your List is not a String.

  • How can i convert some caracteres of a String in bold characteres?? hELPME

    How can i convert some caracteres of a String in bold caracteres?? hELPME
    I have a JList and a DefaultListModel of Strings. So, i have many key words like "proccess", "if", "fi" that i want these characteres in bold.

    How i can use HTML in java to change a String to bold?
    example
    String str = "channel ";
    str = <b>str</b>;
    like this? syntax error =/

  • How can I convert a Waveform to a String-For​mat?

    Hello,
    I write with "SQL-Execute.vi" datas to an Access-file. The "SQL-Execute.vi" needs a statement in String Format. And that is my problem. My source-datas (that I want to save to Access) are Waveforms. How can I convert the Waveform datas to a String Format?
    Thanks for help!

    Wire the waveform to the Get waveform componants function...from that you get t0, delta t and the sample values. Now you can generate whatever string you want based on that information...
    You could e.g. wire the Y array to a for-loop in which you calculate the time of each sample by taking t0 and adding delta t multiplied with the array index, then you could convert the Y value and the time to strings using the seconds to time string and number to fractional string functions...etc etc...
    MTO

  • How can i convert JMS TextMessage into a String

    Please tell me,How can i convert A JMS TextMessage into a String

    http://java.sun.com/javaee/5/docs/api/javax/jms/TextMessage.html#getText()

  • How can I convert/read out from a string Hex (8-bit), the bit 0 length 1

    How can I convert/read out from Hex (8-bit), the bit 0 length 1 (string subset!!??) and convert it to decimal.
    With respect to one complement and two complement ?

    Just like Jeff, purely guessing here.
    It almost sounds like you just need to Read from Binary File?
    AND the 8-bit number with 1?
    Need more details.  What exactly do you have to start with?  What exactly are you trying to get out of it?  Examples help.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • How can I convert Bigint value which produced with Timespan?

    Below from MS SQL, tResultTime's datatype is Bigint
    Below from my C# project's UI and I need to get a result like "Elapsed Time".  How can I get that?

    CREATE TABLE Timing (
    StartTime DATETIME
    ,EndTime DATETIME
    ,ResultTime BIGINT
    ,ElapsedTime VARCHAR(20)
    insert into Timing (StartTIme, endtime) values
    ('2014-11-20 14:35:42','2014-11-28 14:36:15')
    DECLARE @MyNullTime TIME
    SET @MyNullTime = '00:00:00'
    SELECT StartTime,EndTime
    ,DATEDIFF(MILLISECOND, starttime, EndTime) AS 'tResultTime (MS)'
    ,cast(DATEDIFF(HOUR, starttime, EndTime) / 24 AS VARCHAR(5)) + 'day(s) '
    + cast(DATEADD(SECOND, - DATEDIFF(SECOND, EndTime, StartTime), @MyNullTime) AS VARCHAR(8)) AS 'Elapsed Time'
    FROM timing
    -Vaibhav Chaudhari

  • How can i convert BigDecimal value in BigInteger

    Hi Folk!
    I am problem i need to change BigDecimal value in BigInteger. Can anybody tell me how can i do it?
    I Know how to change a BigInteger value in BigDecimal. Here is the code.
    BigInteger bint = BigInteger.valueOf(1231231232);
    BigDecimal input2 = new BigDecimal(input);but I have a BigDecimal how can i do the opposite what i have done in code?
    Thanks in Advance

    I am problem... that's not good.
    (Glad to see you got your problem resolved.)

  • How can I convert date infomation to a string just includes the date not th

    I just want the date like Thu 08, july 2004 but not the exact time.
    how can I do that.

    The prior code produces a date formatted as Jul 7, 2004
    To get Wed 07, July 2004, try this minor modification:
    import java.text.DateFormat;
    import java.util.Date;
    import java.text.SimpleDateFormat;
    DateFormat format = new SimpleDateFormat("EEE dd, MMMM yyyy");
    Date mydate = new Date();
    String str = format.format(mydate);
    System.out.println(str);

  • How can i convert if the date in string format

    String lFstr = (String) pReq.getParameter("FND");
    String lTstr = (String) pReq.getParameter("TND");
    String lLstr = (String) pReq.getParameter("LWD");
    System.out.println(lFstr + " " + lTstr + " " + lLstr);
    //DateFormat ds = DateFormat.getDateInstance();
    DateFormat dateFormatter = new SimpleDateFormat("dd/MM/yyyy");
    Date lFdate = null;
    Date lTdate = null;
    Date lLdate = null;
    try {
    lFdate = dateFormatter.parse(lFstr);
    lTdate = dateFormatter.parse(lTstr);
    lLdate = dateFormatter.parse(lLstr);
    } catch (Exception e) {
    System.out.println(lFdate+" "+lTdate+" "+lLdate);
    i am getting the values from request parameters at that time it is giving values.
    after convertion of string to date it is giving the null value what is wrong in this code

    It might have thrown an exception. Try printing the stack trace in the catch block.

  • How can I erase the last char of string

    I have a string tha is printing as following
    129.111.13.1.
    I want to erase the last "." can somebody helpme?
    Thanks

    You will have to create a new String. Then you can get the string length. Then you will need to to use a substring to get the positions you want.
    Something like this
    String Orginal = "129.111.13.1.";
    String new_orginal = null;
    int num;
    num = Original.length();
    new_orginal = Original.substring(0,num-1);
    I hope it helps

  • How can I convert a tab to a String

    Hello,
    I want to read a file, and check if in some place from the text there is a tab there, in case there exist one, repmplace for <tab8> or something like that.
    I have the following.
    import java.io.*;
    import java.util.*;
    public class Expander {
      // other declarations ...
      public static void expand(String[] args) {
    //    BufferedWriter br = new BufferedReader();
        try{
          if(args[0].equals("-v")){
            System.out.println("Expander Version 1.0\nCopyright (C)");
          if(args[0].equals("-h")){
            System.out.println("");
            System.out.println("Usage: java Expander [OPTION] ... [FILE] ...");
            System.out.println("Convert tabs in each FILE to spaces, writing to standard output.");
            System.out.println("Without FILE or with FILE = -, read from standard input.");
            System.out.println("");
            System.out.println("-i    do not convert TABs after non-whitespace.");
            System.out.println("-i=N  have tabs (positive) N spaces apart, not the default 8.");
            System.out.println("-h    display this help message and exit.");
            System.out.println("-v    display version information and exit.");
          if(args[0].equals("-i")){
            BufferedReader in = new BufferedReader(new FileReader(args[1]));
            String tempLine;
            while((tempLine = in.readLine()) != null){
              String temp = check(tempLine);
              System.out.println(temp);
              writeNew(temp,"1"+args[1]);
          else
            System.err.println("Command not Accepted, please check -h for more help");
        catch(IOException e){System.out.println(e);}
        catch(NoClassDefFoundError i){System.out.println(i);System.exit(0);}
      }// closes readLoadData
      public static String check(String line){
        if ( line.equals("\t") )
          return "<TAB8>";
        else
          return line;
      public static void writeNew(String line, String args){
        String name = args+".txt";
        try
          BufferedWriter out = new BufferedWriter(new FileWriter(name, true));
          PrintWriter fw = new PrintWriter(out);
          fw.print(line);
          out.close();
        catch(IOException e)
        { System.out.println(e);}
      public static void main(String[] args) {
        Expander.expand(args);
    }any ideas?
    Tahnks =)

    Hi,
    I guess the best way is to use regular expressions (must use SDK 1.4.1 or higher):
    Add the line:
    import java.util.regex.*;
    and use one of the methods:
    //Regex method to replace all \\t by <tab>
    public String replaceTabs1(String line, String tab) {
    Matcher matcher = Pattern.compile("\t").matcher(line);
    tab = matcher.replaceAll("<tab>");
    return line;
    //Regex method to replace \\t by <tab> one by one
    public String replaceTabs2(String line) {
    Matcher matcher = Pattern.compile("\t").matcher(line);
    while(matcher.find()){
    line = matcher.replaceFirst("<tab>");
    return line;
    Or, use more general method to find and replace any string by any other string in your file
    public String replaceText(String source, String find, String replace) {
    Matcher matcher = Pattern.compile(find).matcher(source);
    source = matcher.replaceAll(replace);
    return source;
    Hope it will work,
    VM

  • How can I convert (or switch) the RGB percent values from the LR histogram into RGB values which are shown e. g. in PS/CameraRAW?

    In LR 5.5 (same in previous versions) the RGB values in the histogram are shown in percent (relativ) values. I prefere to see the absolute values, but I can`t find any way to switch. Maybe this option is intentional disabled, because LR works in 16-Bit mode this would result in values up to 2^16. But as i compared the relativ values from LR with the absolute values from PS i run into a conversion problem. The following example shows the differences:
    CameraRAW : RGB, 128,0,0
    Lightroom: RGB, 43,8%, 19,0%, 6,2%
    CameraRAW: RGB, 0,128,0
    Lightroom: RGB, 29,8%, 47,5%, 17,5%
    Mainly i have two questions:
    1. Is there any possibility to change the percent RGB values in LR to absolut values?
    2. How can i convert CameraRAW values to LR values (see above)?

    TThe reason that a design decision was made from the beginning of LR to show only the percentage values was that RGB values are dependent on the color space and the LR histogram and numerical readout are derived from the Develop module's display space which is a hybrid color space with ProPhoto RGB primaries and the sRGB TRC. Thus the numerical values in the display would be different from the exported RGB image (in an orthodox space) and it was feared that this would be misleading. When soft proofing was introduced, because it involved converting the display to an orthodox space, it became possible to use the 0-255 scale in that mode.

  • How can I convert an int to a string?

    Hi
    How can I convert an int to a string?
    /ad87geao

    Here is some the code:
    public class GUI
        extends Applet {
      public GUI() { 
        lastValue = 5;
        String temp = Integer.toString(lastValue);
        System.out.println(temp);
        showText(temp);
      private void showText(final String text) {
        SwingUtilities.invokeLater(new Runnable() {
          public void run() {
            tArea2.setText(text + "\n");
    }

Maybe you are looking for

  • Unable to perform call transfer or call park for an outbound call via SIP Trunk (SKYPE)

    We have configured the SIP Trunk & SIP profile and successfull make outbound call through SIP Trunk (SKYPE). However, we are not able to perform call transfer or call park when the call is connected. The scenario is: A call to an phone number via SIP

  • Can't use the keyboard shortcuts in Photoshop CS6 when updating Mavericks

    Can't use the keyboard shortcuts in Photoshop CS6 when updating Mavericks

  • Basics of reports

    hi friends, i am new to reports. I am learning the basics os reports.please  suggest me some sites or else some pdfs so that i can understand the basics of them.my mailid is <b>[email protected]</b>. please help me i need them

  • Tool popups no longer display properly

    My DW CS5.5 is not diplaying popup boxes correctly when selected. For instance when I want to insert a Spry data set, the popup is very small and I can't enlarge it. It does not allow me to go through the steps required to perform the function. Here

  • Iir butterworth bandpass filter

    Hello everyone, I am trying to generate bandpass butterworth filter coefficients for one of my class projects. I am using "Butterworth CoefficientsVI" to generate the filter coefficients and using these coefficents I filter my input signal using "IIR