Truncating Strings(stringbuffer)

Hello again
im trying to delete portions of a string that are over a certain length, i know i need to use StringBuffer and public delete(int start, int end) command, but i am having trouble working it in, how do i initialize a Stringbuffer?
Stringbuffer serverNameBuff=new StringBuffer(serverName); is meant to create a StringBuffercopy of the string serverName, what am i doing wrong?
THankyou
dom

lol damn, sorry, i see now...lowercase b...nevermind, but thanks anyway

Similar Messages

  • Updated to CR 2008 - now have new problem with truncated String fields.

    Hi there
    I'm hoping someone has a simple answer for this one...  notice there's a lot of it on forums but I haven't found an answer.
    Since updating to Crystal 2008 (Crystal 12), we have found that some reports are suddenly truncating string fields at 255 characters, despite the field value being much longer in the database.
    Does anyone know what to do to allow these fields to print in completion?
    Database connection is ODBC RDO.
    regards
    -Karen

    What is the database Oracle, SQL server etc.
    Can you query the database directly with another query tool, eg SQL Server Management Studion or SQL developer/Toad for Oracle.
    You can then run the Crystal query directly and see if its your ODBC connection that is truncating the datafield or Crystal.
    I have memo fields on SQL server with up to 2000 characters and these display in Crystal 2008 without any problem. We use ODBC (RDO) too.
    Ian

  • How to display the multiple lines text in a single - String, StringBuffer

    Hi,
    I have a textarea field named Decription which contains more than one line seperated by new line.I need to display those five lines in a single text without breaking. Is it possible? I am getting ArrayIndexOutOfBoundsException while i reached to the end of the line. Plz help me how to align the below code so that i can display the lines as a single line in my excel sheet.
                        if(op.getDescription()!=null)
                            String[] oppDescs = op.getDescription().split("\n");
                            StringBuffer sb = new StringBuffer();
                            for(int i1=0; i<=oppDescs.length-1;++i1)
                                *writeFile(sb.append(oppDescs[i1]), valueWriter);*
                         } else {
                            writeFile(op.getDescription(), valueWriter);
    private void writeFile(java.lang.Object value,PrintWriter valueWriter)
            if(value!=null)
                valueWriter.print(value);   
        }Thanks and Regards

    previous was java1.5
    heres a 1.1 - 1.4 version
    String[] oppDescs = op.getDescription().split("\n");
    StringBuffer sb = new StringBuffer();
    for(int i = 0; i < oppDescs.length : i++){
      sb.append(oppDescs);
    sb.append( '\t' );
    writeFile(sb.toString(), valueWriter );Edited by: simon_orange on 31-Oct-2008 13:02                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • String & StringBuffer again......

    hi all,
    after coding for 1 year with java (before c++ for years) i used the stringbuffer class for the first time a few days ago.
    i implemented a search which has to do lot's (!) of string operations.
    the search was very slow, so i tried stringbuffer.
    i replaced and changed all the string stuff into stringbuffer stuff - but the performance was still bad...
    so could the following be the problem:
    stringbuffer don't know important functions like 'indexof(String)'.
    so everytime i need indexof (for example), i do the toString() function...
    now my first question:
    is all the stringbuffer advantage gone if i use toString() at one or to places ==> how much performance will this cost (in a loop...)?
    my second question:
    what's faster, deleting the content of an used stringbuffer with delete(int,int) or just creating a new with new stringbuffer(String) ?
    thanx a lot,
    andi

    What you should probably do is use "javap -c" to look at the bytecode produced in your class. Then you can see exactly how many objects are being created for each way of coding the String and StringBuffer operations.
    To answer your question about toString(), it creates an extra String object when called, but does not copy the characters. However, if you subsequently change the original StringBuffer, the characters in it will need to be copied. Therefore, calling toString() and then changing the StringBuffer further can have a serious impact on performance.

  • Truncating strings in UIX below 13 characters

    Hi all,
    I'd like to base a boundValue in UIX on the first character of a String. This sounds simple, but I'm at a loss as to how to do it. What I'd really like would be something like this:
    <boundAttribute name="...">
      <if>
        <comparison type="equals">
          <truncate truncateAt="1" text="${mytext}" />
          <fixed text="-" />
        </comparison>
        value1
        value2
      </if>
    </boundAttribute>But this doesn't work, because, as the help states, "strings shorter than 13 characters will never be truncated"! (Why, by the way? This seems like a weirdly random restriction.)
    EL looks like it's supposed to support functions like startsWith, so I tried the following:
    <boundAttribute name="...">
      <if>
        <dataObject default="${startsWith(mytext,'-')}" />
        value1
        value2
      </if>
    </boundAttribute>But "startsWith" doesn't get recognized.
    This seems so simple that I feel like I must be missing something. Any help would be much appreciated.
    Thanks much,
    Avrom

    I don't know about truncate, but if you don't get that solved .... it' pretty easy to create your own EL functions.
    See:
    Re: Custom EL function
    and the link therein.
    Having a set of your own EL functions can come in pretty handy. For example, I use this for logging purposes. And for lots of other stuff. And since it's so easy to have your own set of functions .... . The online help has a section on this.
    Sascha

  • OutputStream to String/StringBuffer?

    How can I convert a OutputStream into a String or StringBuffer?

    <OutputStream>.toString();In what context do you use this?It is inherited from Object.
    This will give you a "string representation" of the stream object. Normally, this will just return an object identifier. I use this when I'm debugging or printing low level logging messages to help determine exactly which object I'm dealing with.
    - K
    PS - If you want to convert a stream to a String, you probably want to be using a Writer instead of a stream. Writers are character set encoding aware...

  • JNI: Getting String | StringBuffer  to Java from C using input argument

    I've written a native method in C which takes command String from Java, executes the command, and obtains both an integer return_code and a C-string result_string as an output. The return_code goes back to Java from the return statement at the end of the native method...my problem is, that I would like to pass into the native method either a String or StringBuffer, and use that to relay the result_string back to the Java code, as well. Eg., loosely, if I have a
    JNIEXPORT jint JNICALL ExecuteCmd
    (JNIEnv *env, jclass jcls, jstring cmdString, jobject returnBuffer)
    where jobject returnBuffer is a StringBuffer created as StringBuffer(2048), I'd like to take return_string once I have it and do something like
    returnBuffer = env->NewStringUTF(result_string);
    (I know the syntax env->NewStringUTF is a bit different to what's in the JNI book, but it's what works on the HP-UX system I'm using.)
    I know already that this particular bit of code doesn't work. My question is, does the general idea have any potential to work, or am I trying to do something that's impossible?

    Your general approach works just fine. What you have to do is use JNI to find the appropriate method for the StringBuffer class, and invoke it.

  • String & StringBuffer

    Hi,
    Why String objects are Immutable?
    and StringBuffer objects are mutable.
    what is the logic behind this design.
    thanks in advance.

    My theory on this is that Strings occupy fixed contiguous areas of memory. To alter them may corrupt the area of memory that comes immeadiately after a particular String. Therefore it is safe to not let programmers to alter them. A StringBuffer on the other hand overcomes this restriction and will allow expansion of itself by the programmer to other areas of memory, under control of the compiler, when required.

  • String , StringBuffer Performace

    I am trying to concatenate strings. In the following program, f2 and f3 take less than a second while f1 takes about 17 seconds on my P4 1.3 Ghz pc. Any ideas why += operation takes more time.
    public class StringTest
    public static void main(String s[])
    long start_time = System.currentTimeMillis() ;
    if (s[0].equals("1")) f1();
    if (s[0].equals("2")) f2();
    if (s[0].equals("3")) f3();
    long end_time = System.currentTimeMillis() ;
    System.out.println("Time in sec: " + (end_time-start_time)/1000);
    public static String f1()
    String s = "";
    for (int i=0;i<10000;i++)
    s += new String("Helloworld");
    return s;
    public static String f2()
    StringBuffer s = new StringBuffer();
    for (int i=0;i<10000;i++)
    s.append("HelloWorld");
    return s.toString();
    public static String f3()
    String s = "";
    for (int i=0;i<10000;i++)
    s = new String("Helloworld");
    return s;
    }

    It's terrifying indeed...
    Here are my results on a IBM ThinkPad PM 1.7 GHz 512 Mb with Windows XP Pro SP2
    For JVMs from 1.4 to 1.6.
    (I modified the println line to get double result)
    java -version
    java version "1.4.2"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2)
    Classic VM (build 1.4.2, J2RE 1.4.2 IBM Windows 32 build cn142-20040926 (JIT ena
    bled: jitc))
    java StringTest 1
    Time in sec: 1.682
    java -version
    java version "1.5.0_05"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_05-b05)
    Java HotSpot(TM) Client VM (build 1.5.0_05-b05, mixed mode)
    java StringTest 1
    Time in sec: 26.588
    java -version
    java version "1.6.0-beta"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-beta-b59)
    Java HotSpot(TM) Client VM (build 1.6.0-beta-b59, mixed mode, sharing)
    java StringTest 1
    Time in sec: 32.76
    Aaaaaaaaaaaaaaargh!!!

  • Truncating String in Sql Query

    Hi,
    I'm having one location table where the values of location are returned as KC_KansasCity,CHAR_Charlotte,PEW_Pewauke etc,I want to truncate the characters before underscore and also underscore while inserting the data into table.
    Can anybody advise me on how to do this..
    Thanks,
    Anil

    Do you want to query based on the truncated code, or map the values into your object based on the truncated code?
    If you want to truncate the code in a query you can use the Expression substring function.
    If you want to map the code to your object you can use an ObjectTypeConverter in your mapping to handle the conversion if you have a fixed number of code mappings. Otherwise you could use your own custom Converter to handle a more complex conversion.
    James Sutherland

  • NI-Communicator truncates string length

    When using NI-Communicator to send commands to a particular instrument, we have discovered that the NI-Communicator is limiting the length of the string sent to the instrument to 99 characters. This can be observed by using NI-Spy. The same NI-488.2 drivers can be used from another custom program to send much longer strings.
    The user interface to NI-Communicator should be fixed to limit input strings to the same length or this limitation should be fixed.

    Hello Marv,
    The NI-488.2 Communicator is primarily for troubleshooting purposes, which is why it only shows a limited number of characters. GPIB communication is usually done through a program because the responses also need to be parsed and processed. I will, however, submit your request to R&D to have that length re-evaluated.
    Ray K
    NI Applications Engineer

  • String to StringBuffer

    How do i convert String object to StringBuffer object?

    You can initialize a new Stringbuffer to a String
    this way:
    String yourString = "A string";
    StringBuffer sb = new Stringbuffer(yourString);
    Alpha75

  • Flat file truncation issue

    I am attempting to perform a fairly standard operation, extract a table to a flat file.
    I have set all the schemas, models and interfaces, and the file is produced how I want it, apart from one thing. In the source, one field is 100 characters long, and in the output, it needs to be 25.
    I have set the destination model to have a column physical and logical length of 25.
    Looking at the documentation presented at http://docs.oracle.com/cd/E25054_01/integrate.1111/e12644/files.htm - this suggests that setting the file driver up to truncate fields should solve the issue.
    However, building a new file driver using the string 'jdbc:snps:dbfile?TRUNC_FIXED_STRINGS=TRUE&TRUNC_DEL_STRINGS=TRUE' does not appear to truncate the output.
    I noticed a discrepancy in the documentation - the page above notes 'Truncates strings to the field size for fixed files'. The help tooltip in ODI notes 'Truncates the strings from the fixed files to the field size'. Which might explain the observed lack of truncation.
    My question is - what is the way to enforce field sizes in a flat file output?
    I could truncate the fields separately in each of the mapping statements using substr, but that seems counter-intuitive, and losing the benefits of the tool.
    Using ODI Version:
    Standalone Edition Version 11.1.1 - Build ODI_11.1.1.5.0_GENERIC_110422.1001

    bump
    If this is an elementary issue, please let me know what I've missed in the manual.

  • Is there any String format class available in J2ME?

    Hello,
    I am looking for a Formating class which should format a string. For example ( This is Java SE code):
    int num = 999;
                String str = " is my lucky number.";
                String s = String.Format("The Number : %d %s", num, str);I could not find any formatter class nor any direct api from String/StringBuffer class to format a string.
    Any suggestion on this is highly appreciated.
    Thank You.
    Regards,
    DK

    sojourner_jdk wrote:
    Hi DarrylBurke,
    You are right. Its not "Format". String has "format" function ..
    String s = String.format("The Number : %d %s", num, str);Is there such class/api in J2ME?
    Thanks,
    Regards,
    -DKIn J2ME MIDP, [String has no "format" function|http://java.sun.com/javame/reference/apis/jsr118/java/lang/String.html|javadoc].

  • JDBC:KPRB string size limits-NEED HELP!

    Hello All.
    Please, I need your help.
    I have the problems in Oracle 9.2.0.6 with stored java and jdbc:kprb internal driver.
    I try to put string(more than 32K) into LONG-type field using following java class:
    import oracle.sql.CLOB;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.io.Reader;
    import java.io.CharArrayReader;
    public class LongTest {
    public static void insertLong()
    throws Exception {
    Connection con = DriverManager.getConnection("jdbc:default:connection:");
    //generate large string
    StringBuffer stringBuffer = new StringBuffer();
    for (int i = 0; i < 100000; i++) {
    stringBuffer.append("qwerty");
    String st = stringBuffer.toString();
    //put large string to long-type field
    PreparedStatement pst = null;
    try {
    pst = con.prepareStatement("insert into TEST_LONG (ldata) values (?)");
    pst.setString(1, st);
    pst.execute();
    } finally {
    if (pst != null) {pst.close();}
    But I get error from jdbc:kprb about limitation of data size for this type(LONG).
    But it works well in oracle 10.2.0.1...
    Has anybody a solution of how to do this in oracle 9.2.0.6???
    thanx!

    Hi,
    THis is a known limitation in the 92 RDBMS solved in 10g.
    Kuassi http://db360.blogspot.com

Maybe you are looking for