Regarding String builder....

StringBuilder str= new StringBuilder(emptySpaces(1150));
str.replace(1,8, "25632365");
str.replace(9,11, "758");
str.replace(12,14, "235");
str.replace(15,39, "TS610IT AADX 0502744129");
str.replace(40,42,"C13");
str.replace(43,45,"MIB");
str.replace(46,46, "D");
What is wrong with above code?
After each replace statement. if i check the length of the it is increased by 1, when i created string builder the length was defined as 1150, after 1st replace it becomes 1151, after 2nd replace it becomes 1152 and so on ....
Please let me know the error in the code. (My purpose is to define a fixed length string and replace the characters at particular position, the length of the staring should never change)

user8378448 wrote:
What is wrong with above code?In addition to what doremi said, I have two other observations:
1. I suspect you need to be reminded that characters in a StringBuilder are indexed from 0, not 1.
2. You appear to be filling in all the empty space (difficult to tell because of your previous mistake).
If so, why not just use:StringBuilder str = new StringBuilder(1150);
str.append("25632365");
str.append("758");
...rather than 'replace'? You can always pad out any unused characters at the end.
If it's not the case, then replace may still be the way to go.
Winston

Similar Messages

  • Regarding String Replacing ....

    Hi Friends,
    I have some problem regarding String replacing.
    ex.
    I have following string ::
    =================================================
    This is the java manager the main purpose for the jasper is used to create reports.
    And the Java language is very extensible.
    Is this the proper string functions provided by java isn't it ?
    *================================================*
    *i want to replace word "is"  with "IS". but that word is not connected to word like  Th{color:#ff00ff}is{color}*
    *differ from simple separate "{color:#ff0000}is{color}" so Word should not be replaced in This only separate "is"*
    *must be replaced. ?*
    *Any Idea ?*
    *{color}*
    Edited by: Ghanshyam on Sep 14, 2007 4:27 PM

    How about just searching for and replacing
    " is "
    instead of
    "is"
    So, using this code from the Java Developers Almanac 1.4 (2002 Addison-Wesley):-
    static String replace(String str, String pattern, String replace) {>    int s = 0;>    int e = 0;>    StringBuffer result = new StringBuffer();> >    while ((e = str.indexOf(pattern, s)) >= 0) {>       result.append(str.substring(s, e));>       result.append(replace);>       s = e+pattern.length();>  result.append(str.substring(s));
    return result.toString();
    }Your would use:-
    String newStr = replace(originalStr, " is "," IS ");
    Edited by: mad_scientist on Sep 14, 2007 4:16 AM (Sorry about all the edits, just getting used to the formatting on here)
    Edited by: mad_scientist on Sep 14, 2007 4:22 AM
    Edited by: mad_scientist on Sep 14, 2007 4:24 AM

  • Regarding query builder api

    Hi,
       i am able to create image reference but not able to create image path from dam i am putting like this
       map.put("type", "dam:Asset"); is this correct or is there any other way to getpath of image from dam .please let me know
    code------------
    Map<String, String> map = new HashMap<String, String>();
            map.put("path", "/content/dam");
            map.put("type", "dam:Asset");
            map.put("group.p.or", "true"); // combine this group with OR
            map.put("group.1_fulltext", fulltextSearchTerm);
            map.put("group.1_fulltext.relPath", "jcr:content");
            map.put("group.2_fulltext", fulltextSearchTerm);
            map.put("group.2_fulltext.relPath", "jcr:content/@cq:tags");
           log.info("======mapout======"+map);
            Query query = builder.createQuery(PredicateGroup.create(map),session);
            log.info("======query======"+query);
            SearchResult result = query.getResult();
             // log.info("======result======"+result);
                   // iterating over the results
            for (Hit hit : result.getHits()) {
                String path = hit.getPath();
              // ValueMap props = hit.getProperties();
               response.getWriter().write(path);
               //response.getWriter().write(props);
                 log.info("======result======"+result);

    Regarding this:
    map.put("group.2_fulltext.relPath", "jcr:content/@cq:tags");
    Note that it's "jcr:content/metadata/@cq:tags" for assets, and note that full text searching the cq:tags property is not a good idea, since these are IDs, not the tag titles that you see in the UI and when the titles change or a tag is moved/merged, the IDs are not changed. You want to first search in the tags tree to find matching tags and then search for them, using the tagid predicate.

  • Queries regarding Flash Builder and Augmented Reality.

    I am Sarat from India. I'm a software engineer with working knowledge of Java, so Flash AS and OOP are understandable for me. I am working on an augmented reality project. I am quite new to Flash, Adobe Community and I've got some queries regarding Augmented Reality and Flash Builder:
    1. Flash Builder 4.6 comes with a default Flex 4.6 SDK. However, Flex 4.6 SDK wasn't allowing me to compile and run some example files. So I've downloaded Flex 4.0A version from Adobe.com. Now the examples are running fine, but would there be any problem if i try deploying such projects in a website or as a desktop app? Once the code is compiled into a swf file, the flex framework used doesn't make much difference, does it?
    2. Would the AR project run effectively on a website, given various internet/processor speeds worldwide? Would the effectiveness of the AR project, deployed on a website, depend on the number of triangles in the 3D models i.e. dae files? Because as per my understanding heavy models implies more time to download the flash app into the local browser from the internet and more time to render them by the papervision 3D engine right?
    3. Can we develop a stand alone desktop AR app using Flash Builder? Using Adobe AIR we can, i guess. Please refer some tutorial, if possible.
    4. I've seen that we can implement multiple-marker-tracking AR using vectors/arrays in AS. Would there be any performance issues depending on the size of the vectors/arrays used.
    5. Can someone please mention some tips to improve performance of an AR app (desktop app and web app)?
    6. What would be, approximately, the cost of FLARManager, FLARToolkit commercial versions, if you have any idea? I've gone through their website but they did not mention the costs.
    7. Would applying bitmap material to the dae models pull down the web app/mobile app/desktop app performance, given some 4 to 5 dae models in the scene?
    8. Is it advisable to use multiple markers with multiple dae models or single marker with Flash-based GUI option to load different models onto the same marker?
    It would be very helpful for me if someone could answer my above queries.
    Sarat.

    #1, If it compiles then you have no issue. There's no reason at this point not to use 4.6. You should bundle a captive runtime to assure the users computer won't need to have AIR installed at all.
    #2, Papervision is old. Use the Stage3D and/or a wrapper framework. As far as the generic "If I download lots of data will it take the user more time to load it", well, of course. Just don't make the loading experience painful. Entertain them while they way or find ways of displaying data sooner than later. If it's desirable on the web has more to do with the context of the app and the device displaying it. In other words, a phone user would find it easy but obviously not a desktop user.
    #3, Definitely referring you to Google on that one.
    #4, Size always matters, it's common sense. The more you process the harder it is. While I haven't done AR I've used the Microsoft Kinect SDK and ANE and tracking was extremely fast but limited. From what I've seen and your basic built in location and direction hardware on any mobile device you shouldn't have much trouble. Depends on what you're doing.
    #5, This discussion would be way too large for a forum. You'd need to consult a firm experienced in AR development.
    #6, "Applications using the commercial license do not have to provide source code, but must pay a licensing fee. Contact ARToolworks at [email protected] for more information." They will base your price on your product, there is no single price.
    #7, The models could be huge and elaborate or tiny and simple which changes the answer. Consult the answer in #4. Ultimately most people are getting on fast networks with mobile and excessively fast on desktop/wifi. Size matters a lot less than 3 years ago.
    #8, Depends on what you're doing. You have to explain it.

  • Regarding string

    Hi frnds,
                  I have a requirement where i have to find the position numbers of '#' in the complet string.
    can anyone help me how to approach.
    <code>
    REPORT  ZTEST_POSITIONFINDER.
    data : var1 type string .
    var1 = '210651#WHA-588QV#11/26/2007 10:58#527.02#526.99#526.99#17640207#ALLEN K  WITHRAW J#1000#CVGOGG20071118NL02#Approved on link to booking.#'.
    </code>
    help me frnds
    regards,
    satish

    Satish,
      I forgot to add one more line in my earlier mail.Check now this.
    DATA : v_cnt TYPE I,
    v_num TYPE I,
    v_num1 TYPE I,
    v_pos(100).
    var1 = '210651#WHA-588QV#11/26/2007 10:58#527.02#526.99#526.99#17640207#ALLEN K WITHRAW J#1000#CVGOGG20071118NL02#Approved on link to booking.#'.
    v_cnt = strlen( var1 ).
    DO v_cnt TIMES.
    v_count = v_count + 1.
    IF var1+v_num1(v_count) EQ '#' .
    concatenate v_count ',' INTO v_pos.
    v_count  =  v_count + 1.*
    ENDIF.
    ENDDO.
    Write : v_pos.
    Here you can see the # position numbers seperated by coma(,).

  • Regarding string operations and value alignment below heading

    Hi all,
    I have a requirement of sending the data in the form of table in mail thought me program.
    Am sending the mail content form int table.
    The issue is the table getting displayed like this(I used internal table of strings for this)-
    Name            |          Old value               |       New value                              -->Heading string
    Description     |          Material for production of tractors  |  Material for tractors  -->value string1
    weight               |       123   | 124                                                                   -->value string2
    Value 124 should have been well below New value.
    In short am not able to arrange the values (Because of variable length of values)well below table field so that i can distinguish  various values in same row.Please guide me for this issue .
    Thank you,
    Edited by: sanu debu on Mar 22, 2009 1:43 PM

    hi,
    use UNDER option.
    like
    write:
      / 5 text-001(give text ele as carrid)
        10 text-002(give as connid)
    loop at itab into fs_itab.
    write: / fs_itab-carrid under text-001,
               fs_itab-connid under text-002.
    endloop.
    Regards,
    jaya

  • Question regarding Flash builder - mysql

    Hi,
    I created a webapp with flash builder 4.6, I use AMFPHP for the database part.
    If I want to add a person to the db through my app, which has een accent in the name (for example "D'hiet"), it returns an error.
    I don't know where to look for this problem. I assume it has something to do with my database settings, but i'm not sure and I cannot seem to find what I need to change to be able to enter names with accents anyway.
    Hope someone can help me...
    thanks in advance!

    For Solaris10 11/06 Release:
    "The default copy method that is used when you create a Solaris Flash archive is the cpio utility. Individual file sizes cannot be over 4 Gbytes. If you have large individual files, you can create an archive with the pax copy method. The flarcreate command with the -L pax option uses the pax utility to create an archive without limitations on individual file sizes. Individual file sizes can be greater than 4 Gbytes."
    http://docs.sun.com/app/docs/doc/819-6398
    This info for other versions/releases will be in install guide.
    John

  • Regarding String truncation

    Hello all,
    I have got a small problem. Hope you will help me.
    I have got a text String which contains both single byte characters and multi-byte characters mixed up(English characters and non-english characters) which i need to insert into database table. Now the database column is set to store a text of maximum length of 100 bytes so it is required to truncate the string before insertion. Now the problem is when i extract the first 100 bytes from the string, the last character of the string sometimes gets changed( due to extracting only first byte of multi-byte character). The dumbest solution I thought to get around this is something like this:
                    //Here remarks contains the string value
         if (null!= remarks && remarks.getBytes().length > 100 ) {
                          while (remarks.getBytes().length > 100) {
                               remarks = remarks.substring(0, remarks.length()-1 );
                     }I am wondering is there any other elegant solution for this as the loop part is time-consuming and moreover, i am inserting the records in a count of thousands.

    Thanks for your reply
    Why do you have to do that on your own? It's the databases task to correctly truncate a String, if necessary (and inform you of the fact by issuing a Warning).
    But when i insert a string of size greater than 100 bytes i am getting an SQL Exception.
    Also, is the size of the text field really restricted by the number of bytes instead of the number of characters? I've seen that in some DBs (can't remember which ones), but it's a pretty bad idea and fortunately not all do it that way.
    I am using Oracle9i and the size of text field is restricted by the number of bytes.
    Also, your code assumes that the database uses the same encoding as the default locale of the machine running your code. Workaround: find out the encoding of the Database and use that when calling getBytes().Points taken. Thanks.

  • Regarding string functions

    hi all,
    i have a text file as following
    linkstable
    linkname,linkpage
    linkpage
    xxxxxxxxxxxxnow i have to read the file ,ie., i have to get Strings in between the "#" ie.,
    i have to find the occurance of the "# " and then the string between them how can i do this
    do we have any method to find the repeated occurance of a string in java
    could any one help me
    thanks in advance

    A lot of this is going to depend on your definition of "between"
    Text1
    Text2
    Text3
    #Text4#
    In the previous example Text3 is the only answer, Text4 is the only answer, or all of the Texts are the answer, which is it? If you don't know, go back to your teacher and find out--you cannot code for a problem that does not have a known outcome. You need much better problem definition before an algorithm can be developed to provide a solution to code.

  • [CS2/CS3] - PMString & string builder

    Hello,    I am using a class called PMString for creating strings such as a logs and so on. If I have larger file there is a problem with realocation of PMString, it is the same line String and StringBuilder in .NET languages. Please is there way to have also some stringBuilder in InDesign SDK ?  Thank you, marxin

    I know about it that StringBuilder is based in .NET framework and InDesign is different, but is there any possibility of allocation space for a PMString (WideString) if I know that I append string long f.e. 1000 chars ? It is same in SDK containers, f.e. method std::vector<T>.reserve(X) which reserves a space ?
    Thank you, marxin

  • Qustion regarding Query Builder.

    Hi All,
    We need to write a query to get the information like " User having access to all the his report"
    and "List of all the user having access to their reports".
    Thanks.

    I don't think that Query Builder is going to let you query for such questions. This can be done using the BOE SDK, which comes in Java and .NET flavor. The QB only lets you query the CMS DB for certain information related to objects but what you are trying to do will be considered more complex for simple SQL queries via the QB.
    You can post on the SDK Forum for better help on code/samples to do what you are trying to accomplish.

  • A question regarding String

    One String problem confused me.
    String s = "aacc";
    Now, i want to insert "bb" between "aa" and "cc", The result would be that s equals "aabbcc". I had thought to implement it by using insert method. but I was surprised that Class String do not support this method. Could anyone give me a simple way that can do this. thanks a lot.

    Use the StringBuffer class instead. The String class is imutable. It will create a new string when modified.
    StringBuffer b = new StringBuffer("aacc");
    b.insert(2, "bb");

  • Regarding string operations

    Hi All,
    i've a string holding the value as given below.
    AA,17,2/19/2003,"9,999.00",USD,00,10,318,"193,275.31"
    by performing some string operations i want the result string in the format as given below:
    AA,17,2/19/2003,"9999.00",USD,00,10,318,"193,275.31"
      i.e., i want to remove all the commas(,)that are included in between a pair of " " only.
    can anyone provide me a sample code for the same

    Hi vijay,
    A bit complex but works for sure, check the following logic,
    REPORT zsritest.
    DATA: gs_string TYPE string.
    gs_string = 'AA,17,2/19/2003,"9,999.00",USD,00,10,318,"193,275.31"'.
    WRITE: / gs_string.
    PERFORM string_trim CHANGING gs_string.
    *       FORM string_trim                                              *
    *  -->  LS_STRING                                                     *
    FORM string_trim CHANGING ls_string.
      DATA: lt_string TYPE string OCCURS 0 WITH HEADER LINE,
            lv_tabix TYPE i,
            lv_start.
      SPLIT gs_string AT '"' INTO TABLE lt_string.
      CHECK sy-subrc EQ 0.
      CLEAR gs_string.
      LOOP AT lt_string.
        lv_tabix = sy-tabix MOD 2.
        IF lv_tabix EQ 0.
          TRANSLATE lt_string USING ', '.
          CONDENSE lt_string NO-GAPS.
        ENDIF.
        IF lv_tabix EQ 0 OR lv_start EQ 'X'.
          CONCATENATE gs_string lt_string INTO gs_string SEPARATED BY '"'.
          IF lv_start EQ 'X'.
            CLEAR lv_start.
          ELSE.
            lv_start = 'X'.
          ENDIF.
        ELSE.
          CONCATENATE gs_string lt_string INTO gs_string.
        ENDIF.
      ENDLOOP.
      IF lv_start EQ 'X'.
        CONCATENATE gs_string '"' INTO gs_string.
      ENDIF.
      WRITE: / gs_string.
    ENDFORM.
    Hope this helps..
    Sri

  • 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"
    }

  • Regarding String array

    I have a input string in this format
    1     Aviation Lamp     1     Nos     3700     3,7002     Lighting Arrester     1     Nos     1600'     1,6003     Aviataion Lamp Cable     31     Rmt     '     270     8,370
    I can able to display the 3,700 1,600 8,370 these values i want to store in a String array for this i have written code in this way but unable to succeed
    Code:
    String sub="1     Aviation Lamp     1     Nos     3700     3,7002     Lighting Arrester     1     Nos     1600'     1,6003     Aviataion Lamp Cable     31     Rmt     '     270     8,370";
    i=3;
    Matcher tdata = Pattern.compile(("\\d*,\\d{3}"), Pattern.CASE_INSENSITIVE).matcher(sub);//Matching is performed using regular expression here
    while (tdata.find()) {
    for (int ij = 0; ij < i; ij++) {
    table[ij] = tdata.group();
    System.out.println(" Result "+tdata.group());//trying to load values in string array
    System.out.println(" "+tdata.group());
    for (int ik = 0; ik < 3; ik++) {
    System.out.println(" output " + table[ik]);//Displaying only 8,370.
    Any suggestions please welcome
    Praveen

    Hi Praveen
    Matcher tdata = Pattern.compile(("\\d*,d{3}"), Pattern.CASE_INSENSITIVE).matcher(sub);
    From above statement of your code, if u see u have Pattern Object which contain regular expression of
    one digit followed by comma and exactly three digits.
    Than your trying to match your string sub with the above regular expression so this wont match,
    you can confirm by using method tdata.matches() , this method returns true if it matches false if it don't.
    you can use the following code to make your stuff work
    String sub = "1 Aviation Lamp 1 Nos 3700 3,7002 Lighting Arrester 1 Nos 1600' 1,6003 Aviataion Lamp"
    + "Cable 31 Rmt ' 270 8,370";
              String []SplitSub = sub.split("\\s");
              Pattern p = Pattern.compile("\\d,\\d{3,}", Pattern.CASE_INSENSITIVE);
              int ij =0;
              String table[] = new String[SplitSub.length];
              if(SplitSub.length > 1)
                   for(int i =0; i < SplitSub.length ; i++)
                        Matcher m = p.matcher(SplitSub);
                        if(m.matches())
                             table[ij++] = SplitSub[i].substring(0,5);
                             System.out.println(" Result " + SplitSub[i].substring(0,5));

Maybe you are looking for

  • Unable to read DVD video

    I unable to read DVD video discs, although I can read DVD-R and CD. I try to change the region using regionset but with no change. here is the output of vlc, when I try to open DVD: VLC media player 0.8.6b Janus libdvdnav: Using dvdnav version 0.1.10

  • How can I Divide AND Ungroup in an Action?

    In CS5, I created a very handy action that allowed me to, with two paths selected, Divide, Ungroup, and Deselect, resulting in the divided paths without having to do each step manually. In CS6, for some reason this is no longer possible-- if I try to

  • Excluding values from variables selection

    Hi, I would like to exclude certain values from the variable selection. There are several plants available in my InfoProvider. But I only would like to show the plant A100 to A400 in the query selection. Is it possible to realize it without using aut

  • How to delete icloud acount

    i go to settings, icloud i choose delete account it asks me for my password, the problem is i forgot my password and i changed it online but it refuses to accept my new password on the phone, how to delete acc without old password, i also don t use t

  • Oracle 9i SQL Documentation

    Can anyone recommend a good book describing/teaching SQL or PL/SQL programming? Assume a new programmer.