Output String Handling in Java

Hi, guys...............
How can I format my output I have a long text formula which consist of alot of "()","{ }" "[ ]" and some other special char. I want to see in a readable format. This output formula is approximately you can say 1 or 2 pages but there is no any space or a break line e.g. [sdsadadfdfsdffwesdfsdfsdf{sdsdddsd^afasdfadfsdfasdfasdfasdf(asdfaf(asfasdfbvdcbyrey)eyydfhghghshgfghfg)fghfghfg}hfg]hfg$sdfsdfsdfsdg[fsdgdfhd{[dsfassd{sdfsgsggdfbergdfvgg}dfgdfgdfgdfg]gdfgdfgdfgdfgdg(hfghfghsdfhgasdfasdffdghdfhbdfgd^sdfgasdfgdfgdfgdfbsd|dfsdggdfgdfhdgh)dfhdfh}dfhdfhvnbvbnmghmjyky] and so on.....upto more than 1 page. so how can I control my string. which is readable for me.
kind regards
for replying
merry

Do you actually want to read a couple of pages of text without white space?
If the bracket things nest you could output them like code (with the content nested):
   sdsetc {
      asadddetc
      ^
      asasdsetc
   hfg
]It's never going to be easy to read, however.

Similar Messages

  • Concerning String Handling

    Hello To Every One,
    I have a query concerning String Handling.
    String s3 = "Java is a wonderful language";
        System.out.println("s3 is: "+s3);
        System.out.println("lastIndexOf(a, 23) = " + s3.lastIndexOf('a', 23));
        System.out.println("********");
    String s4= "Java is a wonderful language";
        System.out.println("s4: "+s4);
        System.out.println("lastIndexOf(a, 19) = " + s4.lastIndexOf('a', 19));Output is:
    s3 is: Java is a wonderful language
    lastIndexOf(a,23)=21
    s4 is: Java is a wonderful language
    lastIndexOf(a,19)=8what is basic difference in s3.lastIndexOf('a', 23)); and
    s4.lastIndexOf('a', 19));
    that output is lastIndexOf(a,23)=21 and
    lastIndexOf(a,19)=8
    Please clarify..
    Thanks.

    Even without reading the API you should be work out what it is doing
    - by reading the source code for the method.
    - debugging it with a debugger.
    - inferring what it does from its name.
    But reading the API is the most obvious, that what the documentation is for.

  • Doubt in String handling...

    Hi
    Here i have a code snippet.
    public class StringComp
         public static void main(String[] args)
              String a = "abc";
              String b = "def";
              String c = "abcdef";
              String d = "xyz";
              String e = "xyz";
              a+=b;
              System.out.println("Value of a = :" + a);
              System.out.println("Value of c = :" + c);
              System.out.println("Value of d = :" + d);
              System.out.println("Value of e = :" + e);
              if(a==c)
                   System.out.println("TRUE");
              else
                   System.out.println("FALSE");
              if(e==d)
                   System.out.println("TRUE");
              else
                   System.out.println("FALSE");
    if i compile and run this code snippet i am getting the result as
    Value of a = :abcdef
    Value of c = :abcdef
    Value of d = :xyz
    Value of e = :xyz
    FALSE
    TRUE
    here i add the value of a and b to a. so a=abcdef, value of c also abcdef.
    but if i check (a==c) the result is False why??
    Can anyone tell me how the string is handled in java (behind the scene) where they are stored ? and how the == operator works on String?
    thanks in advance
    chithrakumar

    Strings are pooled. This means that if you writeString a = "1";
    String b = "1";you have a good chance that a == b.
    For new Strings (as "abc" + "def" returns), the pool is bypassed. This explains why "abc + "def" != "abcdef". To make sure a String is pooled, use intern (). ("abc" + "def").intern () == "abcdef", guaranteed.
    This is all very opaque behaviour and you shouldn't really rely on this in your code, except in very rare circumstances (extreme performance concerns or if you're stuck with an identity hash map [not that that's very likely]).

  • Use Enum to Switch on Strings where one string is a java reserved word.

    Hi,
    I'm having problems switching on a string using enums, when one of the strings is a java reserved word. Any suggestions would be appreciated. Or maybe even a suggestion that I should just be stringing together if-else if and doing string compares rather than a switch.
    I've been using the following method to switch on strings.
    public enum MyEnum
    foo, bar, novalue;
    public static MyEnum stringValue(String string)
    try { return valueOf(string); }
    catch (Exception e) { return novalue; }
    Then I can switch like
    switch(MyEnum.stringValue( someString )
    case foo:
    break;
    case bar:
    break;
    default:
    break;
    Now I have run into the problem where one of the strings I need to use is "int", which is a reserved word in java, so I have to modify.
    What is the best way to handle this?
    I could just not add it to the Enum and handle it at the switch like this...
    switch(MyEnum.stringValue( someString )
    case foo:
    break;
    case bar:
    break;
    default:
    if(someString.equals("int") {  ... }
    break;
    OR...
    I could change the Enum, and return intx, by checking if the string is "int". I could check before the valueOf, or during the exception, but I know it's not good practice to use Exceptions in the normal execution of your code... as it's not really an exception.
    public enum MyEnum
    foo, bar, intx, novalue;
    public static MyEnum stringValue(String string)
    if(string.equals("int") { return intx; }
    try { return valueOf(string); }
    catch (Exception e) { return novalue; }
    OR...
    public enum MyEnum
    foo, bar, intx, novalue;
    public static MyEnum stringValue(String string)
    try { return valueOf(string); }
    catch (Exception e) {
    if(string.equals("int") { return intx; }
    else return novalue;
    }

    My advice is still to not name the enum the same as the value of the string you want to test for. That page I linked to shows how to have enums with parameters. Then you could have an enum whose name is (say) JavaInt and whose string value is "int".
    But frankly if I wanted to map Strings to actions I would just use a Map<String, Action> instead of trying to force my code into an antique construction like switch.

  • ActiveX server output strings

    I'm working on creating an ActiveX server executable with a number of interfaces. Each interface includes at least a couple methods that need to provide string output. The canonical prototype for such a method would simply accept a pointer to char for the output parameter:
    HRESULT method1(char *outputString);
    The ActiveX server editor dialog for method entries provides options for both input and output strings. If I specify outputString as an "output string", the prototype that's generated is:
    HRESULT method1(char **outputString);
    If I specify that it is an "input string", I get the desired prototype in the generated server code, but the corresponding controller code method specifies this parameter as "const char *", meaning that it can only be read, not written; so this isn't workable.
    If I specify that is an "output char", I also get the desired prototype, but in this situation, the generated code only copies 1 character into the output string; so this isn't workable either.
    So I've tried using the prototype produced for "output string" (see above). My server implementation for this method refers to *outputString, e.g.,
    strcpy(*outputString, "Hello");
    to populate the output parameter. On the client side, I pass in the address of a pointer-to-char that points to a string, e.g., &op where:
    char output[1024];
    char *op = output;
    Each time I invoke this corresponding client-side operation, the server crashes; *outputString in the strcpy function call evaluates to NULL. I'm sure I must have something wrong with my approach here. Is there a preferred approach for handling output strings in an ActiveX server?
    Many thanks in advance!

    I don't know if this is helpful at all, but there is an example that uses output strings, SimpleEXE.cws. It may be beneficial to see how it is handled there. The method in question is the Add method in the IString interface. 
    Steven

  • How to print the output string in inverted commas

    hi all,
    my question is
    like i have a string
    "welcome to java"
    using println statement
    i need to print the above statement in inverted commas
    like the output should appear as
    "welcome to java"

    This sounds like part of some homework but what the
    heck ...
    System.out.println("\\"welcome to java\\"");I was trying to anticipate bugs in this stupid forum sofftware, this should be
    System.out.println("\"welcome to java\"");

  • How to get an XML string from a Java Bean without wrting to a file first ?

    I know we can save a Java Bean to an XML file with XMLEncoder and then read it back with XMLDecoder.
    But how can I get an XML string of a Java Bean without writing to a file first ?
    For instance :
    My_Class A_Class = new My_Class("a",1,2,"Z", ...);
    String XML_String_Of_The_Class = an XML representation of A_Class ?
    Of course I can save it to a file with XMLEncoder, and read it in using XMLDecoder, then delete the file, I wonder if it is possible to skip all that and get the XML string directly ?
    Frank

    I think so too, but I am trying to send the object to a servlet as shown below, since I don't know how to send an object to a servlet, I can only turn it into a string and reconstruct it back to an object on the server side after receiving it :
    import java.io.*;
    import java.net.*;
    import java.util.*;
    class Servlet_Message        // Send a message to an HTTP servlet. The protocol is a GET or POST request with a URLEncoded string holding the arguments sent as name=value pairs.
      public static int GET=0;
      public static int POST=1;
      private URL servlet;
      // the URL of the servlet to send messages to
      public Servlet_Message(URL servlet) { this.servlet=servlet; }
      public String sendMessage(Properties args) throws IOException { return sendMessage(args,POST); }
      // Send the request. Return the input stream with the response if the request succeeds.
      // @param args the arguments to send to the servlet
      // @param method GET or POST
      // @exception IOException if error sending request
      // @return the response from the servlet to this message
      public String sendMessage(Properties args,int method) throws IOException
        String Input_Line;
        StringBuffer Result_Buf=new StringBuffer();
        // Set this up any way you want -- POST can be used for all calls, but request headers
        // cannot be set in JDK 1.0.2 so the query string still must be used to pass arguments.
        if (method==GET)
          URL url=new URL(servlet.toExternalForm()+"?"+toEncodedString(args));
          BufferedReader in=new BufferedReader(new InputStreamReader(url.openStream()));
          while ((Input_Line=in.readLine()) != null) Result_Buf.append(Input_Line+"\n");
        else     
          URLConnection conn=servlet.openConnection();
          conn.setDoInput(true);
          conn.setDoOutput(true);           
          conn.setUseCaches(false);
          // Work around a Netscape bug
          conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
          // POST the request data (html form encoded)
          DataOutputStream out=new DataOutputStream(conn.getOutputStream());
          if (args!=null && args.size()>0)
            out.writeBytes(toEncodedString(args));
    //        System.out.println("ServletMessage args: "+args);
    //        System.out.println("ServletMessage toEncString args: "+toEncodedString(args));     
          BufferedReader in=new BufferedReader(new InputStreamReader(conn.getInputStream()));
          while ((Input_Line=in.readLine()) != null) Result_Buf.append(Input_Line+"\n");
          out.flush();
          out.close(); // ESSENTIAL for this to work!          
        return Result_Buf.toString();               // Read the POST response data   
      // Encode the arguments in the property set as a URL-encoded string. Multiple name=value pairs are separated by ampersands.
      // @return the URLEncoded string with name=value pairs
      public String toEncodedString(Properties args)
        StringBuffer sb=new StringBuffer();
        if (args!=null)
          String sep="";
          Enumeration names=args.propertyNames();
          while (names.hasMoreElements())
            String name=(String)names.nextElement();
            try { sb.append(sep+URLEncoder.encode(name,"UTF-8")+"="+URLEncoder.encode(args.getProperty(name),"UTF-8")); }
    //        try { sb.append(sep+URLEncoder.encode(name,"UTF-16")+"="+URLEncoder.encode(args.getProperty(name),"UTF-16")); }
            catch (UnsupportedEncodingException e) { System.out.println(e); }
            sep="&";
        return sb.toString();
    }As shown above the servlet need to encode a string.
    Now my question becomes :
    <1> Is it possible to send an object to a servlet, if so how ? And at the receiving end how to get it back to an object ?
    <2> If it can't be done, how can I be sure to encode the string in the right format to send it over to the servlet ?
    Frank

  • Finding the key according to string length in java.util.Properties

    Finding the key according to string length in java.util.Properties.
    I know only String length only.

    i need to retrieve the values from the java.util.properties.
    we know that we need to give the key value in order to retrieve the datas.
    but my problem is i will give the length of the key instead of giving the key value but i need to retrieve the datas according to the length of the key.

  • How to handle the java.policy file ?

    Can somebody tell me how to handle the java.policy file?
    I always get java.net.SocketExceptions and java.security.AccessControlExceptions while connecting to an appserver from an applet.
    What do I have to write in the java.policy file, where do I have to place it and do I have to call it in some way form my applet?
    Thanks in advance.
    don call

    The java.policy file goes in your jre installation directory in .../jre/lib/security (there should be one there already).
    I used it to allow otherwise restricted permissions for an applet using javax.comm. Add something like the following to the file:
    grant codeBase "URL:http://yourDomainName/rootDirectoryOfYourApp/*" {
         permission java.security.AllPermission;
    This will give the applet downloaded from your site all permissions. You might want to give only certain permissions, I don't know.
    Teri

  • Problem with output string to command

    hey i have no idea why this aint working
    its a simple output string to command.
    what it is supposed to do is make a new directory given by the input string
    e.g. mkdir /home/luke/dep
    thanks for the help
    //methods input save files
         saveFile = JOptionPane.showInputDialog("Save Files To : ");
         //method command for saving files
         //Stream to write file
         FileOutputStream fout;          
         try { Process myProcess = Runtime.getRuntime().exec("mkdir" + saveFile );
          InputStreamReader myIStreamReader = new InputStreamReader(myProcess.getInputStream());
          fout = new FileOutputStream ("file.txt");
          while ((ch = myIStreamReader.read()) != -1) { new PrintStream(fout).print((char)ch); } }
              catch (IOException anIOException) { System.out.println(anIOException); }

    What you fail to understand is that "aint working" and "Problem with output string to command" tells us absolutely squat about what your problem is. This is the same as saying to the doctor "I'm sick" and expecting him to cure you. As mentioned by Enceph you need to provide details. Do you get error messages? If so post the entire error and indicate the line of code it occurs on. Do you get incorrect output? Then post what output you get, what output you expect. The more effort you put into your question the more effort others will put in their replies. So until you can manage to execute a little common sense then the only responses you will get will be flames. Now is your tiny little brain able to comprehend that?

  • Is File handling in Java Swing possible?

    Hi I need to know whether file handling in Java Swing is possible or not?

    cents wrote:
    Thanks for ur answer.....Actually I just wanted to know whether "Reading from a file" and "Writing to a file" in Java Swing is possible or not?
    Edited by: cents on Mar 16, 2010 9:35 AMWhat did google tell you? Did you see anything interesting in the API?

  • Study security related exception handling in Java

    Hi all,
    I am required to do an indepth study on security-related exception handling in Java, their Pluses and minuses... Can ppl suggest me places where I can get a kick start? Any resource that u know can help me out?
    I appreciate ur help in this regard...FYI, I am a grad student and I am doing this as a part of my course-work...I am writing up a report on this...
    Thanx a bunch, in advance for ur help ppl..

    Take a look at the JAAS API and docs.
    - Saish

  • Output strings from loop into one string

    im trying my best to explain my problem so ber in mind:)
    hey having a bit of trouble with outputing strings from loop
    example
    i typed ab into the textbox
    the output should be 12
    but since it is in a loop it would only output the last string and in this case is 2
    im trying to get both strings from the loop and output strings from loop into one string.
    here is some of my code to understand my problem
    // characters a to f
         char[] charword = {'a','b','c','d','e','f'};
         String charchange ;
      // get text from password textbox
                          stringpassword = passwordTextbox.getText();
                          try {
                          // loop to show password length
                          for ( int i = 0; i < stringpassword.length(); i++ ){
                          // loop to go through alfabet     
                          for (int it = 0; it < charword.length; it++){
                             // if char equals stringwords
                               if (stringpassword.charAt(i) == charword[it]){
                                    System.out.print("it worked");
                                    // change characters start with a
                                    if (charword[it] == 'a'){
                                         charchange = "1";
                                    // change to 2
                                    if (charword[it] == 'b'){
                                         charchange = "2";
                                        }

    Not sure how you are displaying the result but you could display each value as soon as you find it.
    if (charword[it] == 'a'){
        System.out.print("1");
    }If it is in a text field then use append. Or if you really need a String with the entire result then use concatenation.
    if (charword[it] == 'a'){
        charchange += "1";
    }

  • How to deocde a Base64 String in Sun Java ME SDK 3.0(Urgent)

    Hi there, I want to decode a base64 encoded String in Sun Java ME SDK 3.0 , but cant find any solution to this, after doing search related to this I found that it's very easy to decode a Base64 string in Sun Wireless Toolkit 2.5 using following code:
    import com.sun.midp.io.Base64;
    byte[] data = Base64.decode(EncodedString);
    But I found that it's not possible in Java ME SDK as com.sun.midp.io.Base64 is not available there, anyone please give me some alternative of above code so that I can decode a Base64 String in Java ME SDK.
    Eagerly waiting for the possible solution.

    Can you please let us know as how you solved the problem? Since we are developing a blackberry app, we found base64 class for blackberry development. We have plans of doing the same in android, not sure whether they have this. As long as we have generic base64 class that can be used in any client device, that would be great. I did a lot of research and could not fine. Please give us the solution.

  • Can formula node take string input and output string?

    I am wondering if the formula node can take string input variable and output string variable after calculation. otherwise I have to output integers and then use case structure to select different output strings, that is kind of redundant in coding.
    ping

    If you are just trying to read lines that have mixed formatting, you don't need any script nodes.
    Can you attach a tpyical flne and a description of the desired read operation so we have a better idea what you are trying to do? Do all lines have the same overall format?
    LabVIEW Champion . Do more with less code and in less time .

Maybe you are looking for

  • Dreamweaver code view letter spacing issue

    Good Morning at all, This morning when i've started DreamWeaver i've seen something change. As you can see in the picture below in the code view, the letters spacing is became really bigger than the normal. In the picture below i've done a piece of c

  • Calling WS from PL/SQL using WS-security

    Hi All, Has anyone experience with calling a Webservice from PL/SQL and use WS-security to encrypt the contents? If not; maybe with java stored procedures in 9i? (in other words: using WS-security without JDeveloper). with regards, Michiel Kuperus

  • Java script void on a site that was working!

    I keep getting a javascript error message at the page below. When I hit the view record I get the message. It HAS been working for me all day today and now just froze with that message. I did check my Firefox preferences and the enable javascript is

  • Best practice migration 10.4.11 G4 PPC to Intel server

    We are ready to upgrade our aging server to a new Intel system. I am wondering the easiest approach. The current server is not running the Universal 10.4. I don't believe there is any viable option that doesn't require lots of hands on rebuilding to

  • LiveType in FCE looks funny

    I exported a video (SD) with a livetype title at the beginning. The video, when watched on a tv, looks fine but the title looks rough. It looks like the quality could be better. I just dropped the .ipr file into my timeline. What should I do to make