About trim() for String

I am doing assignment to deal with the xml code,for every line I read by BufferedReader I have to trim() it,I mean to take away all the white space in this line before I do something with the xml code.but I cannot make it right.the "trim()" seems doesn't work.
so I write some small code to test it,
while(in.ready())
String line = in.readLine();
line.trim();
System.out.println();
but,unfortunately,I found the "trim()" mothod in String does't work,it does't do anything!
because on the screen,it print out the excatly same thing as these code
while(in.ready())
String line = in.readLine();
System.out.println();
it did't take away the white sapce.
can you help me?thank you very much!

here is my xml code:
<database>
     <product>
          <id>No.1</id>
          <name>skateboard</name>
          <type>sports</type>
          <price>$58</price>
     </product>
     <product>
          <id>No.2</id>
          <name>bicycle</name>
          <type>sports</type>
          <price>$122</price>
     </product>
</database>
i suppose to have it print out like:
<database>
<product>
<id>No.1</id>
<name>skateboard</name>
<type>sports</type>
<price>$58</price>
</product>
<product>
<id>No.2</id>
<name>bicycle</name>
<type>sports</type>
<price>$122</price>
/product>
</database>

Similar Messages

  • About trim function capabulity

    Hi Experts,
    I have a some doubts regarding trim function.
    1)trim function any limitations like it will trim for this munch length string(consider adding space also)? please consider in case of trimming spaces
    Regards,
    Surya

    Hi, Surya,
    surya wrote:
    Hi Experts,
    I have a some doubts regarding trim function.
    1)trim function any limitations like it will trim for this munch length string(consider adding space also)? please consider in case of trimming spaces Good idea; let's simplify the conversation by saying we only want to trim spaces.
    TRIM removes all of the spaces, regardless of how many there are.
    If you want to limit the number of spaces it removes, then you have to use other functions, either in addition to or instead of TRIM. (REGEXP_REPLACE comes to mind quickly.)
    I'm not sure what you're saying about "adding space also". LPAD and RPAD are rather like opposites of LTRIM and RTRIM. (There is no bi-directional PAD function.) RTRIM can remove spaces from the end of a string, RPAD can add spaces to the end of a string.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, showing some strimgs you want to change), and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using.

  • Where we can find the detail infomation about the Value String of automatic

    Where we can find the detail infomation about the Value String of automatic?
    such as WE06,WE01 and so on.

    Hai,
               Value string keys are for SAP internal usage. It is just a pointer to the transaction event key which is necessary for automatic account determination.
               Movement types are linked to transaction keys via valuation string in OMWN T-code.
               The R/3 System automatically determines the value string assigned to a specific transaction. It depends partly on entered parameters manually and partly on parameters derived internally by the system. The value string contains all posting transactions that are possible for a certain transaction. The program decides which of these posting transactions lead to G/L account postings in individual cases. You cannot define this in Customizing.
    Value string WE01, for the goods receipt for a purchase order into stock, contains transactions BSX and WRX.
    WE01: BSX, WRX, PRD, KDM, EIN, EKG, BSV, FRL, FRN, BSX, UMB.
    WA14: BSX ,PRD, BSX, UMB
    WA01: BSX, GBB, PRD, BSX, UMB
    Value string RE05 contains transactions BSX and UMB.
    In the standard system, value string WE01 is assigned to goods receipts (and also cancellations and return deliveries) for Standard and Subcontracting purchase order items without account assignment concerning valuated material into stock. In the case of (valuated) goods receipts for purchase order items not subject to account assignment,
    post the items to a stock account using the transaction key BSX and make an offsetting entry to a GR/IR clearing account. A price difference posting (transaction key PRD) is only used if the valuated material is subject to standard price control and if the order price (or invoice price) is different from the standard price. Transaction key KDM is required in Inventory Management for purchase orders in foreign currencies because of differences in exchange rates between goods receipts and invoice receipts, unless the material can not be debited or credited because it is subject to standard price control.
    The transaction keys EIN and EKG (and possibly FRE – see account determination for delivery costs) are only used in company codes where purchase account management is active (as required in France and Belgium for example).
    The transaction keys BSV, FRL, and FRN are only used for the Subcontracting item category.
    Value string WA14 is defined for deliveries without charge (movement type 511).
    The following scenarios are possible:
    Delivery without charge for material subject to moving average price control &#8594; No accounting document
    Delivery without charge for material subject to standard price control (and if the posting date is in the previous period – standard price in the posting period = standard price in the current period) &#8594; Inventory posting (receipt at standard price) and offsetting entry to price differences account
    Delivery without charge for material subject to standard price control, with posting date in the previous period and the standard price in the posting period is different to the standard price in the current period &#8594; Inventory posting (receipt at standard price) and offsetting entry to price differences account (posting in the previous period) &#8594; Stock correction posting and Revenue/expense from revaluation (posting in the current period)
    In the standard system, value string WA01 is assigned to goods issues and other goods receipts. The R/3 System uses an additional influencing factor, account grouping, to differentiate further between the various movements during account determination.
    Hope it will be Helpful 4 u.
    Reward Point if Useful.

  • Relational Operators for Strings

    hi
    i wanted to know if there is some way to get relational operators for strings like you have for numbers (!=,<,>,ect).
    i already know of the .equals()
    what about the string equivalent of != ? or < and >
    i was thinking .codePointAt() with int relational operators could work for </> but thats clunky and still doesn't fix the problem of lack of !=
    i want to know this so i can alphabetize a list of strings; any information about a string organizing method would be helpful also
    thanks

    The API answers all of that for you, but are you serious about "!=" ?
    If you know that "==" (not "=") is "translated" to a.equals(b) then you should know how to translate "!=".
    If not, then try this: !a.equals(b)Keep in mind that comparison operations in Java are not magical "desidors", but rather simply evaluate into a boolean value. You can do whatever you want with this boolean value, including negating it.
    So if you've got two int variables a and b, then "a != b" and "!(a == b)" will have the same result.

  • Compareto versus equals performance for strings equality

    Hi
    Just wanted to know whether compareto and equals method performance for checking whether the two strings are equal or not .
    Which one is good with respect to bytecode , speed performance.
    Im not asking for the difference, only asking which one is good to use most number of times for comparing two strings for equilaty.
    Thanks.

    Hi
    Ya they are both for different purposes. No doubt.
    t which one is faster among the two for string
    equality?
    compareto or equals.
    thanksHis point is that it doesn't matter. You shouldn't worry about optimization for small details like this. Unless you are profiling your code and find a large slowdown with that code, then don't worry about their performance. Use the one that best suits your purpose. If you want to know if they're equal, use equals(), if you want to know their order, use compareTo().

  • To trim a string

    How could i trim a string from 29 bytes to 22 bytes.Please let me know ASAP

    // assuming myString is length 29.
    myString = myString.substring(0, 22);That's 29 characters, not 29 bytes. If you really mean bytes, you can do something like this:
    byte[] myArray = myString.getBytes[]
    byte[] newArray = new byte[22];
    for (int count = 0; count < newArray.length; count++) {
       newArray[count] = myArray[count];
    }Michael Bishop

  • Jdeveloper shouldn't suggest not using new + contructor for Strings

    Hullo all,
    I found a snippet of code on the net which was quite instructive . 5 string creation/assignments and 5 equality tests :
    String s1 = "abc";
    String s2 = s1;
    String s5 = "abc";
    String s3 = new String("abc");
    String s4 = new String("abc");
    System.out.println("== comparison :" + (s1 == s5));
    System.out.println("== comparison : " + (s1 == s2));
    System.out.println("Using equals method : " + s1.equals(s2));
    System.out.println("== comparison : " + s3 == s4);
    System.out.println("Using equals method : " + s3.equals(s4));
    now, in Jdev11g if you create a String using "new" it grumbles about it : "superfluous string constructor should be removed"
    However, it turns out that String s1 = "zzz" and String s1 = new String("zzz") are very different things in java.
    Run the code above to see what I mean. There are five comparison tests. You would expect them all to be "true" but
    the fourth comparison : System.out.println("== comparison : " + s3 == s4); returns FALSE.
    My understanding is that this is due to the optimization of "immutibility of strings" When you say :
    String s1 = "zzz" and String s2 = "zzz" then the characters "zzz" exist only once in the heap and both s1 and s2, secretly, reference the same storage, at least until the value is changed.
    However using the 'new' keyword forces the JVM to create two separate strings, hence the false result for test #4.
    It's nit-picking I know, but I personally found the above code snippet quite instructive, which shows the difference between the statements.

    Hi Colin,
    good point about the difference in how specifc JVM's (my assumption) can treat this differently.
    You can turn off this behaviour via Preferences->Audit->Profiles->Edit then under Rules->API->String Constructor
    Best,
    John

  • A PDF document with information about activation for CS6 software

    Here's a PDF document with information about activation for CS6 software.
    I found it very useful for understanding how the system worked for activation of perpetual licenses, both in cases where the computer is and isn't connected to the Internet.

    Ann, with some browsers, the PDF document will download in the background rather than appear in a browser window.

  • "buffer too small for string or missing null byte" inserting CR in excel

    I have created a Crystal Report based on below stored procedure.
    DELIMITER $$
    DROP PROCEDURE IF EXISTS `ww_test`.`PRD_Data_sp` $$
    CREATE PROCEDURE `ww_test`.`PRD_Data_sp` (in cyear int, in cmonth int, in groupby varchar(20), in Inv_type varchar(4))
    BEGIN
      select
              CASE WHEN groupby='Date' THEN  (p.FKDAT)
                   WHEN groupby='SalesOrg' THEN  CONCAT(p.VKORG,'_',p.VTWEG)
              END ,
              sum(p.QTYSAM),
              sum(p.CASESSOLD),
              sum(p.SOLDDOL)
              from ww_test.prd_data p
              where (month(p.FKDAT)=cmonth and year(p.FKDAT)=cyear) and
                     ((p.FKART) is null or not(p.FKART in ("FAZ","ZMBB","FAS",Inv_Type))) and
                     ((p.AUART) is null or not(p.AUART in ("ZMBB")))
              Group by
                  CASE WHEN groupby='Date' THEN  (p.FKDAT)
                       WHEN groupby='SalesOrg' THEN  CONCAT(p.VKORG,'_',p.VTWEG)
                  END
              Order by
                  CASE WHEN groupby='Date' THEN  (p.FKDAT)
                       WHEN groupby='SalesOrg' THEN  CONCAT(p.VKORG,'_',p.VTWEG)
                  END;
    END $$
    DELIMITER ;
    I have used Add Command to create report based on this.
    call ww_test.prd_data_sp({?Year},{?Month},{?GroupBy},{?InvType});
    I am able to refresh the report in crystal and as well in Infoview without any problem.
    But when i try to insert this report in Excel using Live Office it gives me error. I able to insert other crystal reports without any problem.
    An error occurred while opening the report. The report does not exist; you have insufficient rights to open the report; or you cannot make a connection to the BusinessObjects Web Service. (LO 02010)
    Failed to open report (LO 26619)
    Cannot open report document 
    Buffer too small for string or missing null byte.
    can anyone suggest where i am going wrong? Any input is appreciated.
    Crystal Reports 2008
    Live Office XI 3.1
    BOEdge XI 3.1
    Xcelsius 2008
    Thanks ,
    Madhavi

    With the CurrentValue method
    Crpt.ParamFields[3].CurrentValue := memo1.Text;
    Is there another solution ?

  • Buffer too small for string - Crystal Report for Vs2010

    Hello,
        I have recently upgrade my VS2010 project to Crystal Report for Visual Studion 2010.
        I have some reports that contains more than 512 characters in the Report Comments section.
        When I try to do a RptDoc.SaveAs(vPath, false) the following error is raised:
    Buffer too small for string or missing null byte.
          at CrystalDecisions.ReportAppServer.ClientDoc.ReportClientDocumentClass.SaveAs in :line 0
          at CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.SaveAs in :line 0
          at CrystalDecisions.CrystalReports.Engine.ReportDocument.SaveAs in :line 0
        This line SaveAs was working has expected with Crystal Report 2008. Any idea on why it is not working anymore.
    Thank you.
    Charles

    Hello Don,
        I have start a little project to retest the behavior.
       I have create a new report in Crystal Report 2008 just by clicking New, Finish and Save.
       In a new Windows Application in Vs2010 ,I have added the following Crystal Report Reference.
        CrystalDecisions.CrystalReports.Engine, Version=13.0.2000.0
       CrystalDecisions.Shared, Version=13.0.2000.0
    I have then try the following code and found out the limit of ReportComment is 511 but in the Crystal Report 2008 designer and runtime the limit did not apply.
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
          Dim objRpt As New CrystalDecisions.CrystalReports.Engine.ReportDocument()
          Dim i As Integer = 0
          Try
             objRpt.Load("c:\temp\empty.rpt", CrystalDecisions.Shared.OpenReportMethod.OpenReportByTempCopy)
             Do
                i += 1
                objRpt.SummaryInfo.ReportComments = New String("X", i)
             Loop
             objRpt.SaveAs("c:\temp\dfh_save.rpt", False)
          Catch ex As Exception
             MsgBox("i: " & i)
             MsgBox(ex.Message)
          End Try
    End Sub
         I am able to put has many characters if I insert the report in the Vs2010 Solution.
         If you prefer I can send you my little project.
    Thank you.
    Charles
    <code> should be
    Edited by: Don Williams on Feb 4, 2011 12:47 PM

  • How to setup trim for 256GB SSD for Yosemite OS 10.10.1 on Mid 2010 MacBook Pro

    What is the best way to setup effective TRIM for a newly installed SanDisk Ultra Plus 256 GB  (old version) drive on a mid 2010 MacBook Pro 6,2 with 8 GB RAM and running just installed Yosemite OSs 10.10.1?  The new operating system is not referenced by SanDisk.   Thank you.

    Thank you and to others that responded,   I will take the advice to not enable trim at this time,but will visit the issue at a much later date.   Maybe Apple will find a way to securely allow us to TRIM 3rd party SSDs.   Iwill look at an annual manual TRIM in a year or so, if that is a good solution. Does this approach sound reasonable?   This is my first ever post to this problem solving group.  Thanks again also to ALL previous contributors.
    Roger

  • I need information on my bill, for the last two yrs, how do i go about looking for it

    i need information on my bill for the last two yrs, how i go about looking for it . thanks\

    The last 12 months' worth can be obtained via your on-line MyVerizon account; look under View Bill and use the drop-down to select the appropriate bill.  Anything prior to the past 12 months would need to be obtained via Customer Service; there is a charge (I believe $5 per copy, but I'm not sure).

  • Program for string comparision in ABAP

    Hi,
    I require a program in abap for string comparision

    Comparing Strings
    Similarly to the special statements for processing strings, there are special comparisons that you can apply to strings with types C, D, N, and T. You can use the following operators:
    <operator>
    Meaning
    CO
    Contains Only
    CN
    Contains Not only
    CA
    Contains Any
    NA
    contains Not Any
    CS
    Contains String
    NS
    contains No String
    CP
    Contains Pattern
    NP
    contains No Pattern
    There are no conversions with these comparisons. Instead, the system compares the characters of the string. The operators have the following functions:
    CO (Contains Only)
    The logical expression
    <f1> CO <f2>
    is true if <f1> contains only characters from <f2>. The comparison is case-sensitive. Trailing blanks are included. If the comparison is true, the system field SY-FDPOS contains the length of <f1>. If it is false, SY-FDPOS contains the offset of the first character of <f1> that does not occur in <f2> .
    CN (Contains Not only)
    The logical expression
    <f1> CN <f2>
    is true if <f1> does also contains characters other than those in <f2>. The comparison is case-sensitive. Trailing blanks are included. If the comparison is true, the system field SY-FDPOS contains the offset of the first character of <f1> that does not also occur in <f2>. If it is false, SY-FDPOS contains the length of <f1>.
    CA (Contains Any)
    The logical expression
    <f1> CA <f2>
    is true if <f1> contains at least one character from <f2>. The comparison is case-sensitive. If the comparison is true, the system field SY-FDPOS contains the offset of the first character of <f1> that also occurs in <f2> . If it is false, SY-FDPOS contains the length of <f1>.
    NA (contains Not Any)
    The logical expression
    <f1> NA <f2>
    is true if <f1> does not contain any character from <f2>. The comparison is case-sensitive. If the comparison is true, the system field SY-FDPOS contains the length of <f1>. If it is false, SY-FDPOS contains the offset of the first character of <f1> that occurs in <f2> .
    CS (Contains String)
    The logical expression
    <f1> CS <f2>
    is true if <f1> contains the string <f2>. Trailing spaces are ignored and the comparison is not case-sensitive. If the comparison is true, the system field SY-FDPOS contains the offset of <f2> in <f1> . If it is false, SY-FDPOS contains the length of <f1>.
    NS (contains No String)
    The logical expression
    <f1> NS <f2>
    is true if <f1> does not contain the string <f2>. Trailing spaces are ignored and the comparison is not case-sensitive. If the comparison is true, the system field SY-FDPOS contains the length of <f1>. If it is false, SY-FDPOS contains the offset of <f2> in <f1> .
    CP (Contains Pattern)
    The logical expression
    <f1> CP <f2>
    is true if <f1> contains the pattern <f2>. If <f2> is of type C, you can use the following wildcards in <f2>:
    for any character string *
    for any single character +
    Trailing spaces are ignored and the comparison is not case-sensitive. If the comparison is true, the system field SY-FDPOS contains the offset of <f2> in <f1> . If it is false, SY-FDPOS contains the length of <f1>.
    If you want to perform a comparison on a particular character in <f2>, place the escape character # in front of it. You can use the escape character # to specify
    characters in upper and lower case
    the wildcard character "" (enter # )
    the wildcard character "" (enter # )
    the escape symbol itself (enter ## )
    blanks at the end of a string (enter #___ )
    NP (contains No Pattern)
    The logical expression
    <f1> NP <f2>
    is true if <f1> does not contain the pattern <f2>. In <f2>, you can use the same wildcards and escape character as for the operator CP.
    Trailing spaces are ignored and the comparison is not case-sensitive. If the comparison is true, the system field SY-FDPOS contains the length of <f1>. If it is false, SY-FDPOS contains the offset of <f2> in <f1> .
    DATA: F1(5) TYPE C VALUE <f1>,
          F2(5) TYPE C VALUE <f2>.
    IF F1 <operator> F2.
       WRITE: / 'Comparison true, SY-FDPOS=', SY-FDPOS.
    ELSE.
       WRITE: / 'Comparison false, SY-FDPOS=', SY-FDPOS.
    ENDIF.
    The following table shows the results of executing this program, depending on which operators and values of F1 and F2.
    <f1>
    <operator>
    <f2>
    Result
    SY-FDPOS
    'BD '
    CO
    'ABCD '
    true
    5
    'BD '
    CO
    'ABCDE'
    false
    2
    'ABC12'
    CN
    'ABCD '
    true
    3
    'ABABC'
    CN
    'ABCD '
    false
    5
    'ABcde'
    CA
    'Bd '
    true
    1
    'ABcde'
    CA
    'bD '
    false
    5
    'ABAB '
    NA
    'AB '
    false
    0
    'ababa'
    NA
    'AB '
    true
    5
    'ABcde'
    CS
    'bC '
    true
    1
    'ABcde'
    CS
    'ce '
    false
    5
    'ABcde'
    NS
    'bC '
    false
    1
    'ABcde'
    NS
    'ce '
    true
    5
    'ABcde'
    CP
    'b'
    true
    1
    'ABcde'
    CP
    '#b'
    false
    5
    'ABcde'
    NP
    'b'
    false
    1
    'ABcde'
    NP
    '#b'
    true
    5
    goto sap library if intsalled in ur system and check the above one....

  • Wat should be the regular expression for string MT940_UB_*.txt to be used in SFTP sender channel in PI 7.31 ??

    Hi All,
    What should be the regular expression for string MT940_UB_*.txt and MT940_MB_*.txt to be used as filename inSFTP sender channel in PI 7.31 ??
    If any one has any idea on this please let me know.
    Thanks
    Neha

    Hi All,
    None of the file names suggested is working.
    I have tried using - MT940_MB_*\.txt , MT940_MB_*.*txt , MT940*.txt
    None of them is able to pick this filename - MT940_MB_20142204060823_1.txt
    Currently I am using generic regular expression which picks all .txt files. - ([^\s]+(\.(txt))$)
    Let me know ur suggestion on this.
    Thanks
    Neha Verma

  • ORA-13223: duplicate entry for string in SDO_GEOM_METADATA table and

    I got the above error while trying to insert a record into the table SDO_GEOM_METADATA. However, when querying this table I did find any duplicate table_name, column_name pair that match with the error.
    Here are the steps that I worked on:
    1. Add a geometry column into an existing table.
    ALTER TABLE GEO_MAP ADD (ORG_GEOM mdsys.sdo_geometry);
    2. Register the new column into mdsys
    insert into USER_SDO_GEOM_METADATA
    values ('GEO_MAP','ORG_GEOM',
    mdsys.sdo_dim_array(
    mdsys.sdo_dim_element('LONG',-180,180,0.00005),
    mdsys.sdo_dim_element('LAT',-90,90,0.00005)
    8307)
    I got the error ORA-13223: duplicate entry for string in SDO_GEOM_METADATA table even there was no such record in there.
    3. I inserted values in the column ORG_GEOM fine.
    4. However, when I tried to create the index for this column I got the error:
    ORA-29855: error occurred in the execution of ODCIINDEXCREATE routine
    ORA-13203: failed to read USER_SDO_GEOM_METADATA view
    ORA-13203: failed to read
    Please help.
    Thanks.

    SQL> select * from mdsys.sdo_geom_metadata_table;
    SDO_OWNER SDO_TABLE_NAME
    SDO_COLUMN_NAME
    SDO_DIMINFO(SDO_DIMNAME, SDO_LB, SDO_UB, SDO_TOLERANCE)
    SDO_SRID
    QW_USER1 GEO_REF
    LOC_GEOM
    SDO_DIM_ARRAY(SDO_DIM_ELEMENT('LONG', -180, 180, .00005), SDO_DIM_ELEMENT('LAT',
    -90, 90, .00005))
    SDO_OWNER SDO_TABLE_NAME
    SDO_COLUMN_NAME
    SDO_DIMINFO(SDO_DIMNAME, SDO_LB, SDO_UB, SDO_TOLERANCE)
    SDO_SRID
    8307
    MDSYS SDO_CMT_CBK_RTREE_TAB
    GEOM
    SDO_DIM_ARRAY(SDO_DIM_ELEMENT('X', -180, 180, .000000005), SDO_DIM_ELEMENT('Y',
    SDO_OWNER SDO_TABLE_NAME
    SDO_COLUMN_NAME
    SDO_DIMINFO(SDO_DIMNAME, SDO_LB, SDO_UB, SDO_TOLERANCE)
    SDO_SRID
    -90, 90, .000000005))
    The situation is we have 2 tables (GEO_MAP, and GEO_REF) that have spatial columns. Everything worked fine until when one of the queries that searched through the table GEO_MAP ran so slow, we decided to rebuild the related spatial index by dropping and recreating it. However, after I dropped it I could not recreated. Keep getting the error:
    ORA-29855: error occurred in the execution of ODCIINDEXCREATE routine
    ORA-13203: failed to read USER_SDO_GEOM_METADATA view
    ORA-13203: failed to read
    Any help is very much appreciated.

Maybe you are looking for