String doubt

String str = "124 | Testing Message | Process | I | Norm | 14/08/2001 | future";
The above given string is a message .
In the above string u may seen " | " (pipe )symbol after every element.
it may also come like
"1245 | Testing Message Process | Processor | I | Norm | 14/08/2001 | future";
so length may differ.
what i need exactly is i would like to know the index position of " I ".
how can i do that?

you could use
int index = str.indexOf("| I |")+2;
of course, you could use str.indexOf('I');
but i think the part between first and second '|' could include an 'I'
hope it helps
Harry

Similar Messages

  • Please Help !  Simple question !

    Hi all,
    Please anybody tell me why the following line
    <input type="text" name="price" value="<%=myBean.getPrice()==0.0?"":myBean.getPrice()%>">gives me the error:
    incompatible types for ?: neither is a subtype of the other
    second operand: java.lang.String
    third operand : float
    out.print(myBean.getPrice()==0.0?"":myBean.getPrice());
    ^
    1 error
    I am doing this in JSP.
    Please help and reply soon.
    Please reply soon.................
    Waiting for your reply !
    Thanks
    amitindia

    Like annie said, change the method to return a String (doubt if you want this)
    or
    <%=myBean.getPrice()==0.0?"":""+myBean.getPrice()%>

  • Doubt in String Equals

    Doubt in String Equals_
    if(filePath != "") {
         getExcelData(filePath);
    }same as
    if(!filePath.equals("")) {
         getExcelData(filePath);
    }The can both be used interchangeably right ?

    kajbj wrote:
    (You should really open a textbook and read about Strings, or google)fortunatly i know this :)
    if you do
    String str = "abc"
    str =="abc" // will always return true.
    but str==(new String("abc")) // will always return false.
    But as per the query posted i am referring to the first case :)

  • Doubt about  a null value assigned to a String variable

    Hi,
    I have a doubt about a behavior when assigning a null value to a string variable and then seeing the output, the code is the next one:
    public static void main(String[] args) {
            String total = null;
            System.out.println(total);
            total = total+"one";
            System.out.println(total);
    }the doubt comes when i see the output, the output i get is this:
    null
    nulloneA variable with null value means it does not contains a reference to an object in memory, so the question is why the null is printed when i concatenate the total variable which has a null value with the string "one".
    Is the null value converted to string ??
    Please clarify
    Regards and thanks!
    Carlos

    null is a keyword to inform compiler that the reference contain nothingNo. 'null' is not a keyword, it is a literal. Beyond that the compiler doesn't care. It has a runtime value as well.
    total contains null value means it does not have memory,No, it means it refers to nothing, as opposed to referring to an object.
    for representation purpose it contain "null"No. println(String) has special behaviour if the argument is null. This is documented and has already been described above. Your handwaving about 'for representation purpose' is meaningless. The compiler and the JVM don't know the purpose of the code.
    e.g. this keyword shows a hash value instead of memory addressNo it doesn't: it depends entirely on the actual class of the object referred to by 'this', and specifically what its toString() method does.
    similarly "total" maps null as a literal.Completely meaningless. "total" doesn't 'map' anything, it is just a literal. The behaviour you describe is a property of the string concatenation operator, not of string literals.
    I hope you can understand this.Nobody could understand it. It is compete nonsense. The correct answer has already been given. Please read the thread before you contribute.

  • Doubt about string.intern()

    Hello
    I have a doubt about string.intern() method.
    The document says
    When the intern method is invoked, if the pool already contains a string equal to this String object as determined by the String.equals(Object) method, then the string from the pool is returned.
    So what is the point of using this intern() method with == or != operators if it aleady calling to equals method internally?
    eg:
    if (studentObject.getName().intern() == "Student Name") {}cannot be better than
    if (studentObject.getName().equals("Student Name")) {}Can someone please explain?

    Easy dude.
    >
    Why do you need to optimize it?>
    Because i want to.
    I would avoid the whole stupid 100 line if-else by doing a Map of type->object and then just clone() the object. But maybe that might not be suitable or "fast enough" for you.I cannot do above because object have it's own behaviors varying at run time
    eg - class One has setOne method and class hundred has setHundred method
    . Even if i use a map and clone it again i have to use above comparison for setting those behaviours.
    Explain your actual problem you're trying to solve, with actual cases. What are these "one" and "Hundred" classes really? Or is your project so top secret that you can't tell us?It is not secret but big. And I need to make the question understandable. If I post the whole code no one will looking at it.
    Now you asking so please have a look.
    still I have cleaned up many.
    My initial question was how to bit speed up the comparison? And can't i use intern() Because here if I got plenty of rectangles(it is the last) performace sucks.
    for (CObject aObject : objList) {
                if (aObject.getType().equals(SConstant.TEMPLATE)) { /* process Template */
                    Template tObj = (Template) aObject;
                    org.apache.velocity.Template template = VelocityTemplateManager.getInstance().getObjectTemplateFromFile(retemplateProperties.getProperty("PAGE"));
                    VelocityContext context = new VelocityContext();
                    StringWriter writer = new StringWriter();
                    context.put(retemplateProperties.getProperty("BAND_OBJECT"), dtmBand);
                    tObj.setTags(writer.toString());
                } else if (aObject.getType().equals(SConstant.LINE)
                        && !isInBandandBandAutoAdjust(aObject)) {
                    Line object = (Line) aObject;
                    org.apache.velocity.Template template = VelocityTemplateManager.getInstance().getObjectTemplateFromFile(retemplateProperties.getProperty("LINE"));
                    VelocityContext context = new VelocityContext();
                    StringWriter writer = new StringWriter();
                    updateContextWithCheckShifting(context, object);
                    context.put(retemplateProperties.getProperty("LINE_OBJECT"), object);
                    template.merge(context, writer);
                    object.setTags(writer.toString());
                } else if (aObject.getType().equals(SConstant.IMAGE) /* process Image */
                        && !isInBandandBandAutoAdjust(aObject)) {
                    REImage imageObject = (REImage) aObject;
                    org.apache.velocity.Template template = VelocityTemplateManager.getInstance().getObjectTemplateFromFile(retemplateProperties.getProperty("IMAGE"));
                    VelocityContext context = new VelocityContext();
                    updateContextWithCheckShifting(context, imageObject);
                    context.put(retemplateProperties.getProperty("IMAGE_OBJECT"), imageObject);
                    mageObject.setTags(writer.toString());
                   else if (aObject.getType().equals(SConstant.RECTANGLE) /* process Rectangle */
                        && !isInBandandBandAutoAdjust(aObject)) {
                    Rectangle rectangleObject = (Rectangle) aObject;
                    org.apache.velocity.Template template = VelocityTemplateManager.getInstance().getObjectTemplateFromFile(retemplateProperties.getProperty("RECTANGLE"));
                    VelocityContext context = new VelocityContext();
                    StringWriter writer = new StringWriter();
                    updateContextWithCheckShifting(context, rectangleObject);
                    context.put(retemplateProperties.getProperty("RECTANGLE_OBJECT"), rectangleObject);
                    template.merge(context, writer);
                    rectangleObject.setTags(writer.toString());
                }And masijade
    Thank you very much for the better explanation.

  • ORA-02050 transaction string rolled back, some remote DBs may be in-doubt

    Hi...guys...How ru all...
    I got follwoing error...and I searched in google but there is not clear information..plz help me ...
    Error Message: ORA-02050 transaction string rolled back, some remote DBs may be in-doubt
    Error Cause:
    Network or remote failure during a two-phase commit.
    Action:
    Notify operations; remote databases will automatically re-sync when the failure is repaired.
    SQL>SELECT local_tran_id, global_tran_id, state, mixed, host, commit#
    FROM dba_2pc_pending
    LOCAL_TRAN_ID GLOBAL_TRAN_ID STATE MIX HOST COMMIT#
    5.44.98254 JICRACDB.e1ab4089.5.44.98254 collecti no JICN\ROOM9 1132915640
    ng 7-ITC
    SQL> SELECT local_tran_id, in_out, database, dbuser_owner, interface
    2 FROM dba_2pc_neighbors
    3 /
    LOCAL_TRAN_ID IN_OUT DATABASE DBUSER_OWNER INT
    5.44.98254 in JIC N
    5.44.98254 out RC_DBLINK JIC N
    SQL> ;
    1 select state, tran_comment, advice from dba_2pc_pending
    2* where local_tran_id ='5.44.98254'
    SQL> /
    STATE TRAN_COMMENT ADVICE
    collecting
    so how can I delete distributed transaction..plz provide me any Metalink Docids.

    See if following MOS note helps.
    Manually Resolving In-Doubt Transactions: Different Scenarios (Doc ID 126069.1)

  • ORA-01591: lock held by in-doubt distributed transaction string  error

    Hi Gurus,
    I am getting the error
    ORA-01591: lock held by in-doubt distributed transaction string error while running once procedure.
    Procedure basically inserts 2 tables and update 1 table.
    The order of execution is given below.
    However I get the error as table _a locked.
    Can you please help me how to handle this ?
    Begin
    Insert into table_a values (values1, value2); -- (our DB)
    Insert into table_b@remote_DB values (value1, value2); --( REMOTE DB)
    update table C ; -- (our DB)
    commit; -- when I debugged I get exception with the sql error above in this commit.
    End;

    Tina wrote:
    Hi Gurus,
    I am getting the error
    ORA-01591: lock held by in-doubt distributed transaction string error while running once procedure.
    Procedure basically inserts 2 tables and update 1 table.
    The order of execution is given below.
    However I get the error as table _a locked.
    Can you please help me how to handle this ?
    Begin
    Insert into table_a values (values1, value2); -- (our DB)
    Insert into table_b@remote_DB values (value1, value2); --( REMOTE DB)
    update table C ; -- (our DB)
    commit; -- when I debugged I get exception with the sql error above in this commit.
    End;
    01591, 00000, "lock held by in-doubt distributed transaction %s"
    // *Cause:  Trying to access resource that is locked by a dead two-phase commit
    //          transaction that is in prepared state.
    // *Action: DBA should query the pending_trans$ and related tables, and attempt
    //          to repair network connection(s) to coordinator and commit point.
    //          If timely repair is not possible, DBA should contact DBA at commit
    //          point if known or end user for correct outcome, or use heuristic
    //          default if given to issue a heuristic commit or abort command to
    //          finalize the local portion of the distributed transaction.

  • Doubt in concatenating strings

    Hi all,
    Am concatenating two strings and i want space of 10 characters.
    If i use concatenate text1 text2 into text3 separated by space
    it is dispalying as : text1 text2
    But my requirement is to display text with gap of 10 characters
    ::::::text1                               text2

    Hello,
    If u want to use it in ALV then u should do like this.
    I have did the same thing for TOP_OF_PAGE do the same for end_OF list
    GO therough this code..
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
           EXPORTING
                I_CALLBACK_PROGRAM          = IT_VARIANT-REPORT
    <b>            I_CALLBACK_HTML_TOP_OF_PAGE = 'TOP_OF_PAGE'</b>     <b>Herechange to END_OF_LIST</b>        IT_FIELDCAT                 = IT_FIELDCAT
                I_SAVE                      = 'A'
                IS_VARIANT                  = IT_VARIANT
                IT_EVENTS                   = IT_EVENTS
           TABLES
                T_OUTTAB                    = G_T_OUTTAB
           EXCEPTIONS
                PROGRAM_ERROR               = 1
                OTHERS                      = 2.
    FORM TOP_OF_PAGE USING CL_DD TYPE REF TO CL_DD_DOCUMENT.    "#EC *
      DATA: L_F_INFO(255).
      DATA: LV_COUNT TYPE SDYDO_TEXT_ELEMENT,
            LV_PER TYPE SDYDO_TEXT_ELEMENT,
            LV_NUMC(8) TYPE N.
      CALL METHOD CL_DD->ADD_TEXT
        EXPORTING
          TEXT         = TEXT-008
          SAP_STYLE    = CL_DD_DOCUMENT=>SMALL
          SAP_COLOR    = CL_DD_DOCUMENT=>LIST_HEADING_INT
          SAP_FONTSIZE = CL_DD_DOCUMENT=>SMALL
          SAP_EMPHASIS = CL_DD_DOCUMENT=>STRONG
          STYLE_CLASS  = SPACE.
      CALL METHOD CL_DD->NEW_LINE
        EXPORTING
          REPEAT = 1.
      CALL METHOD CL_DD->ADD_GAP
        EXPORTING
          WIDTH = 25.
      CALL METHOD CL_DD->ADD_TEXT
        EXPORTING
          TEXT         = TEXT-009
          SAP_STYLE    = CL_DD_DOCUMENT=>SMALL
          SAP_COLOR    = CL_DD_DOCUMENT=>LIST_HEADING_INT
          SAP_FONTSIZE = CL_DD_DOCUMENT=>SMALL
          SAP_EMPHASIS = CL_DD_DOCUMENT=>STRONG
          STYLE_CLASS  = SPACE.
      CALL METHOD CL_DD->ADD_GAP
        EXPORTING
          WIDTH = 10.
      CALL METHOD CL_DD->ADD_TEXT
        EXPORTING
          TEXT         = TEXT-010
          SAP_STYLE    = CL_DD_DOCUMENT=>SMALL
          SAP_COLOR    = CL_DD_DOCUMENT=>LIST_HEADING_INT
          SAP_FONTSIZE = CL_DD_DOCUMENT=>SMALL
          SAP_EMPHASIS = CL_DD_DOCUMENT=>STRONG
          STYLE_CLASS  = SPACE.
      CALL METHOD CL_DD->ADD_GAP
        EXPORTING
          WIDTH = 11.
      CALL METHOD CL_DD->ADD_TEXT
        EXPORTING
          TEXT         = TEXT-011
          SAP_STYLE    = CL_DD_DOCUMENT=>SMALL
          SAP_COLOR    = CL_DD_DOCUMENT=>LIST_HEADING_INT
          SAP_FONTSIZE = CL_DD_DOCUMENT=>SMALL
          SAP_EMPHASIS = CL_DD_DOCUMENT=>STRONG
          STYLE_CLASS  = SPACE.
      CALL METHOD CL_DD->ADD_GAP
        EXPORTING
          WIDTH = 15.
    Hope this will be help ful for u.
    If useful reward.
    Vasanth

  • 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]).

  • Doubt in Strings

    I have a string suppose 80000.00000
    i want to strip off the zeros after the decimal point..and show only 80000 ..how do i do it?/.,Please help

    rajaram: substring() not subString() and str not "str"
    @OP Do you know in advance that everything after the dot will be zero? If not, you will have to check for that. Depending on what you are trying to do (rather than how you are trying to do it) you may be able to avoid having the zeros in the first place by properly formatting an int value.

  • Doubt in compareTo method while sorting string having special character

    I used compareTo method of String to sort below strings
    ??che
    ??in
    p?ch?
    I got the output in the below order :
    p?ch?
    ??che
    ??in
    Why does ??che appear before ??in because from http://www.asciitable.com/ ascii value of *?* is *154*
    and that of *?* is *130* so shouldn't ??in appear ??che?
    Regards,
    Joshua

    jaay wrote:
    I used compareTo method of String to sort below strings
    ??che
    ??in
    p?ch?
    I got the output in the below order :
    p?ch?
    ??che
    ??in
    Why does ??che appear before ??in because from http://www.asciitable.com/ ascii value of *?* is *154*
    and that of *?* is *130* so shouldn't ??in appear ??che?
    Regards,
    JoshuaAre you sure your strings are using ASCII encoding, and not unicode? If it's the latter, the ASCII table won't matter at all and you'd need to check the values in a unicode table.

  • Doubt in String Parsing

    Hi,
    "23:BE|2009:A@Banglore"
    i need to parse the above string and retrieve the data's.
    Now i am using the StringTokenizer and my code is this,
    String sz = "23:BE|2009+A@Banglore";
              StringTokenizer szTkn = new StringTokenizer(sz, ":");
              System.out.println(" : " + szTkn.nextToken());
              szTkn = new StringTokenizer(szTkn.nextToken(), "|");
              System.out.println(" | " + szTkn.nextToken());
              szTkn = new StringTokenizer(szTkn.nextToken(), "+");
              System.out.println(" + " + szTkn.nextToken());
              szTkn = new StringTokenizer(szTkn.nextToken(), "@");
              System.out.println(" @ " + szTkn.nextToken());
              System.out.println(" " + szTkn.nextToken());is there any good way to do this?

    vijay wrote:
    You can use backreferencing to capture any group in a matching patterns.
    Take a look at this:
    http://download.oracle.com/javase/tutorial/essential/regex/groups.html
    I don't see how 'backreferencing' comes into this since the OP only needs the content of field values between separators without any direct reference to what has been found before.
    Since the original code suggests the fields are always there and always in the same order I think it is easier still just to use split()
    String sz = "23:BE|2009+A@Banglore";
    String[] splitSz = sz.split("[:|+@]");

  • Doubt in String

    Hi Members,
    Is there any method to check whether a string contains any special characters or not.
    Venkat

    just use the link posted above, and keep a look out for "Since: 1.5"
    Or:
    http://java.sun.com/j2se/1.4.2/docs/api/
    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html

  • Doubt in String class

    What is the exact difference between
    String s=new String("xxxxxxx");
    String s="xxxxxxx"; ?
    Please let me know
    rgds
    Mohan S

    Read the Java Language Specs people.
    If I do this:
    String a = "A";
    String b = "A";How many "A"'s are in memory?
    The answer: 1.
    Doing this:
    String a = new String("A");First thing that happens is that "A" will be put in memory. Then a reference to "A" will be created (new String()), then your creating a reference (String a) and assigning your new String to it.
    The new String() creates a new object referencing the same string in memory.
    Hope this clarifies.
    It's explained better in JLS
    3.10.5 String Literals
    4.3.3 The Class String
    And the VM Spec
    2.3 Literals
    String literals and, more generally, strings that are the values of constant expressions are "interned" so as to share unique instances, using the method String.intern.

  • Basic Doubt regarding string comparision

    I have the following code:
    RegisterForm rf = (RegisterForm)form;
    String user = rf.getUsername();
    DTO ourdto = DBconnection.getDTO();               
    String pass = ourdto.getPword();When I print user,*pass* both the strings print "*pojo*"
    Now the condition I have to satisfy is
    pseudo code ---- if(*user* isequal to pass) { proceed forward }.
    I have used .equals but it is returning false,used equalsIgnoreCase and isContentEquals both are returning false.
    Could someone tell me if there is any method that can compare "pojo" to "pojo" and return a true.
    .

    sidster wrote:
    I have used .equals but it is returning false,used equalsIgnoreCase and isContentEquals both are returning false.Then they're not equal.
    Could someone tell me if there is any method that can compare "pojo" to "pojo" and return a true.
    String str = getUserInputOrWhatever();
    if ("pojo".equals(str)) {
      // the string was "pojo"
    }

Maybe you are looking for

  • Oracle 8.1.6 Installation fails with java.lang.NullpointerException

    HI, We are installing Oracle 8.1.6 on a D Class machine running HPUX 11.0 OS While i start the Universal Installer, it fails with the following error. Warning: Missing charsets in String to FontSet conversion Warning: Cannot convert string "-dt-inter

  • ITunes for my iPad 2 iOS 6.01 won't work.

    iTunes for my iPad 2 iOS 6.01 won't work. When I open it it shows me the iTunes U page and wont't open the normal iTunes Help! P.S. I tried to restore it a few times but it doesn't work.

  • Adobe apps funky in 10.4.6

    I recently did an erase and reinstall to work around the bug in which the QT 7.0.4 update invalidates the QT Pro key... Anyway, so now I have 10.4.6 on my machine, my system and all the apps are only a few days old. I use Photoshop and Illustrator a

  • No sound in os x 10.10.2

    I updated to os x 10.10.2 earlier and now I have no sound in safari why is this?

  • Supplementary excise duty

    In some of the cases, the purchase order is made without specifying excise duty amount when the material is received from traders.  In normal course traders do raise the bill on basic price and excise duty amount and subsequently when they clear the