Remove some portion of the String

Hi,
My problem is String contains data is
artist1
title1
-1
artist2
title2
2
artist3
title3
-1
artist4
title4
2
i want to remove some portion of the string like artist2, title2, 2 so my updated string should be like
artist1
title1
-1
artist3
title3
-1
artist4
title4
2
Here i am using String.replaceAll("artist2","");
String.replaceAll("title3","");
String.replaceAll("2","")("[\code]
its deleting whole data in a string, can any one please help me how to delete particular part of the string. Here artist and title are unique and no are reapeated.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Hey I had the same problem like you yesterday.
I tried using regEx with positiv lookahead but noticed that there was a problem when the String went over multiple lines. There is probably some solution to it that i havent found yet.
So what I did was get the Index of the first text I wanted deleted(in your case I guess "artist2"). Then got the Index of the end of the deletion point(In your case the "2"?) and then formed a new String with the substring from the orginal one and the indexes of the two deletion points.
Sounds kinda dirty but it did work out. Anyway I'll dig myself into regular expressions more today because if you get them to work, they're a charm :)

Similar Messages

  • Need some help with the String method

    Hello,
    I have been running a program for months now that I wrote that splits strings and evaluates the resulting split. I have a field only object (OrderDetail) that the values in the resulting array of strings from the split holds.Today, I was getting an array out of bounds exception on a split. I have not changed the code and from I can tell the structure of the message has not changed. The string is comma delimited. When I count the commas there are 26, which is expected, however, the split is not coming up with the same number.
    Here is the code I used and the counter I created to count the commas:
    public OrderDetail stringParse(String ord)
    OrderDetail returnOD = new OrderDetail();
    int commas = 0;
      for( int i=0; i < ord.length(); i++ )
        if(ord.charAt(i) == ',')
            commas++;
      String[] ordSplit = ord.split(",");
      System.out.println("delims: " + ordSplit.length + "  commas: " + commas + "  "+ ordSplit[0] + "  " + ordSplit[1] + "  " + ordSplit[2] + "  " + ordSplit[5]);
    The rest of the method just assigns values to fields OrderDetail returnOD.
    Here is the offending string (XXX's replace characters to hide private info)
    1096200000000242505,1079300000007578558,,,2013.10.01T23:58:49.515,,USD/JPY,Maker,XXX.XX,XXX.XXXXX,XXXXXXXXXXXXXXXX,USD,Sell,FillOrKill,400000.00,Request,,,97.7190000,,,,,1096200000000242505,,,
    For this particular string, ordSplit.length = 24 and commas = 26.
    Any help is appreciated. Thank you.

    Today, I was getting an array out of bounds exception on a split
    I don't see how that could happen with the 'split' method since it creates its own array.
    For this particular string, ordSplit.length = 24 and commas = 26.
    PERFECT! That is exactly what it should be!
    Look closely at the end of the sample string you posted and you will see that it has trailing empty strings at the end: '1096200000000242505,,,'
    Then if you read the Javadocs for the 'split' method you will find that those will NOT be included in the resulting array:
    http://docs.oracle.com/javase/6/docs/api/java/lang/String.html#split(java.lang.String)
    split
    public String[] split(String regex)
    Splits this string around matches of the given regular expression.  This method works as if by invoking the two-argument split method with the given expression and a limit argument of zero. Trailing empty strings are therefore not included in the resulting array.
    Just a hunch but your 'out of bounds exception' is likely due to your code assuming that there will be 26 entries in the array and there are really only 24.

  • Removing some songs at the same time

    Hi, i've got a problem with my itunes, i've got my music all mixed up and moved atleast 8 times all around the computer, but now the itunes has got about 7-8 copies of every song, and to remove these you have to select one by one to get them removed. I need something just to remove the ones that don't have a location or not working. I also tryed removing them all but then i'll loose my top rated list and this is about 95 songs and to put these back, it will take hours. So please if there is an option which i don't now about or another program that could sort that out, that would be great, please tell me as soon as possible. Thanks, Besho2005
    Qosmio g20   Windows XP Pro  

    Go here
    http://ottodestruct.com/blog/category/geekery/programmery/
    Otto42 is a regular poster on discussions. He wrote some java scripts.
    Get the FindDeadTracks and RemoveDeadTracks scripts, read his directions on downloading and using them, and run them.

  • On certain websites, e.g. Craigslist, some portions of the window overlay other portions. How do I fix this?

    Most websites view correctly, however there are a few which show portions of site overlaying other portions. E.g., on Craigslist, when I view a category page such as "for sale-auto parts", the heading "auto parts" is partially over the "search for" box, and the "in:" box extends to the right far enough that it blocks the "search" button. I've tried about a dozen CL locations and they all show the same issue.
    I've tried zooming the page in and out but the problem doesn't change.
    Another issue is that on search pages such as duckduckgo.com, loading of search-result pages is very show.

    If you have increased the minimum font size then try the default setting "none" in case the current setting is causing problems.
    *Tools > Options > Content : Fonts & Colors > Advanced > Minimum Font Size (none)
    Make sure that you allow websites to choose their fonts.
    *Tools > Options > Content : Fonts & Colors > Advanced > [X] "Allow pages to choose their own fonts, instead of my selections above"
    *http://kb.mozillazine.org/Websites_look_wrong
    *https://support.mozilla.org/kb/Websites+look+wrong
    *https://support.mozilla.org/kb/Changing+fonts+and+colors
    It is better not to increase the minimum font size, but use an extension to set the default page zoom to prevent issues with overlapping text.
    *Default FullZoom Level: https://addons.mozilla.org/firefox/addon/default-fullzoom-level/
    *NoSquint: https://addons.mozilla.org/firefox/addon/nosquint/

  • How can I remove the brackets in the middle of the string.

    Hi,
    This is String str = “Hello (buntty and dumbu) how are you?”
    When I used String token[]=s.split(" "); it splits the string
    Hello
    (buntty
    and
    dumbu)
    how
    are
    you?
    I want the string str= “Hello buntty and dumbu how are you?”
    Please help to remove that “(“brackets from the string.
    Thanks
    Buntty

    Use String.replaceAll()

  • Some portion of phone screen not working.

    I bought my iphone 4 in december 2011 from UK.
    Its incurring a problem from past 2 weeks. Some portion in the middle is not working which disables me from using key 7, 8, 9 in the phone keypad of making calls. I tried reseting my phone but the problem still exists. Since I reside in India, I cant get it corrected from Apple service centre in India and there is no scope of me going UK by December 2012.
    What should I do? Please suggest me.

    I have exact same problem. Top portion won't respond and Apple was not helpful at all.
    The options presented to me were:
    -199.00 for a replacement
    -99.00 for 3g
    -199.00 for 3gs
    None of the above were acceptable solutions for I too spent alot for a device which I expected to last more than 2 years.
    I would have been ok with a discount on an upgrade to a 3gs but I paid full price and bought the service plan becuase I anticipate a problem with my 3gs within 2 years.

  • Remove regular expression from a string

    Hello,
    I have a string like this
    @1test;'"{input+
    Please help me to remove special characters from the string.

A: remove regular expression from a string

Hi Krishna,
DATA : str TYPE STRING VALUE '@1test;"{}]input+',
            char,
            length TYPE i,
            index TYPE i.
length = STRLEN( str ).
WHILE length > index.
  char = str+index(1).
  WRITE char.
  if char CA '+-*/!`@#$%^&()_=[]{};'.               " Add/Remove here to include numbers
    REPLACE ALL OCCURRENCES OF char in str WITH ''.
    REPLACE ALL OCCURRENCES OF '"' in str WITH ''.  " characters "{}[] are not comparable
    REPLACE ALL OCCURRENCES OF '{' in str WITH ''.
    REPLACE ALL OCCURRENCES OF '}' in str WITH ''.
    REPLACE ALL OCCURRENCES OF '[' in str WITH ''.
    REPLACE ALL OCCURRENCES OF ']' in str WITH ''.
    length = STRLEN( str ).
    ENDIF.
  add 1 to index.
ENDWHILE.
WRITE str.
Add or remove special char from '+-*/!`@#$%^&()_=[]{};' in if part as per your requirement.
Hope it meets your requirement.
Do not forget to mark helpful/correct if ma answer is useful .
Thanks,
Karthik

Hi Krishna,
DATA : str TYPE STRING VALUE '@1test;"{}]input+',
            char,
            length TYPE i,
            index TYPE i.
length = STRLEN( str ).
WHILE length > index.
  char = str+index(1).
  WRITE char.
  if char CA '+-*/!`@#$%^&()_=[]{};'.               " Add/Remove here to include numbers
    REPLACE ALL OCCURRENCES OF char in str WITH ''.
    REPLACE ALL OCCURRENCES OF '"' in str WITH ''.  " characters "{}[] are not comparable
    REPLACE ALL OCCURRENCES OF '{' in str WITH ''.
    REPLACE ALL OCCURRENCES OF '}' in str WITH ''.
    REPLACE ALL OCCURRENCES OF '[' in str WITH ''.
    REPLACE ALL OCCURRENCES OF ']' in str WITH ''.
    length = STRLEN( str ).
    ENDIF.
  add 1 to index.
ENDWHILE.
WRITE str.
Add or remove special char from '+-*/!`@#$%^&()_=[]{};' in if part as per your requirement.
Hope it meets your requirement.
Do not forget to mark helpful/correct if ma answer is useful .
Thanks,
Karthik

  • Extend the String Class

    Is there a way to extend the string class? I know it's final, if i make my class final too would that work? I want to add some functionality to the string class, but I wanna be able to do concatination with the + operator and stuff like that. That's special to the String class.
    Any help would be great.
    Thanks.
    Joe

    Well, put your mind at easy with the fact that being
    able to use the '+' operator on Strings is a design
    flaw in Java. At least from a purist point of view...And from a pragmatist's point of view, it's a reasonable compromise, the benefit of which outweighs the downside. This is consistent with Java's goal as a good general-purpose language. It's not intended to be pure OO or pure anything else.

  • Would removing some rows cause Row Currency issues?

    Here is my story
    Clicking a link goes to a table. The table looked fine, scrolling to next page as expected. For some strange reason, I started getting row currency errors. So I added "EnableTokenValisdation=false" on pagedef. Then I realized that I could not scroll to the next page. It has like 50 records. However, when I try to go to the next set (or if try to View All records), I get no row found. Why? Help!
    Now I am stuck.

    Frank, I agree. I removed the kludge.
    Now, how can this happen. I have a application that worked.
    I remove some rows from the database using sqldeveloper.
    I retry the same app and I get row currency errors. Is this a possibility and if so, what can be done or how can I find the problem?
    I have closed the app several times, deployed it, rebuilt uit several times.

  • Addressing of part of the string in the container

    Hello,
    in a mail task I would like to print only some characters from a string - e.g. from second to tenth - is it possible to address some part of the string in the container as is usual in abap?
    thx,
    JJ

    Hi,
    Yes , it is possible. If you want to show only some part of the string value in mail description you can use normal abap string operations. For example: In Mail description if you want to show only a part variable VALUE. you can just use &VALUE+a(b)&. It will work !!
    You can try it out !!
    Regards
    Krishna Mohan

  • How do I copy the string portion of an enum into the string portion of a cluster?

    I want to do this for the an entire array of clusters.  I'm trying to use a for loop.  Can't figure out how to parse the string portion of the enum into the string portion of the cluster.
    Alternatively, I'd be happy if I could figure out some way to tie the enum to the array of clusters, but I figure that gets problematic.
    DH
    Solved!
    Go to Solution.

    Dark Hollow wrote:
    OK, let's say that the enumerated type has N elements.  I want to initialize an N element array of strings.  How do I reference each string in the enumerated type to get to each string?
    Easy way to do this is to use GetNumericInfo.vi, part of the Variant library, found in vi.lib\utility\VariantDataType\GetNumericInfo.vi.  Wire your enumeration to the Variant input; one of the outputs is an array of the strings in the enumerated type.
    The more complicated way is a for loop, in which you typecast the iterator terminal value to the enumerated type, then use Format Value.  You can get the maximum value of the enumeration by casting 0 to the enumerated type, then decrementing; cast that back to a numeric and add one to get the right value to wire to the N terminal.
    EDIT: just thought I'd add, since RavensFan's reply popped up while I was writing mine - I don't like the Strings[] approach because it doesn't work on RT targets, and I lost a lot of time once due to this trying to figure out why my code wouldn't run properly on an RT system but worked great on my development computer.

  • Using ps trying to remove an object from a picture, following steps but when object is removed area is replaced by another portion of the photo like someones face as opposed to what should normally be in the background

    using PS on a regular computer windows 7 tryng to remove an object from a picture,  following steps in the tutorial however when the object is removed it is replaced by another (unwanted) portion of the photo i.e. someones face  instead of what would have normally been in the background

    Well, we can't know. You have not told us what tools you use and what steps nor provided any screenshots. From your description it simply sounds like you are following some tutorial (which again we know nothing about because you haven't told us which one) and getting things wrong. You need to do much better if you want people to help you.
    Mylenium

  • Removing number appended at the end from a string field

    Hi,
    I have a string field which has numbers appended to its end. I need to remove the numbers and display only the string values.
    The string is not of fixed length, and the numeric values can be single digit or 2 digits and might be separate by a space but not always.
    Here is some sample data:
    SHOWCASE NOTT12
    SHOWCASE PETE12
    SHOWCASE BRIST7
    SHOWCASE READI1
    CINEDROME PAD1
    RITZ BELPER   1
    STEPH.JOSEPH S1
    I need to display this as below (without any numbers appended at the end)
    SHOWCASE NOTT
    SHOWCASE PETE
    SHOWCASE BRIST
    SHOWCASE READI
    CINEDROME PAD
    RITZ BELPER  
    STEPH.JOSEPH S
    Please let me know how this can be achieved.
    Thanks!

    Hi there,
    Just a quick option is to use the REPLACE function, i.e.
    REPLACE(REPLACE(REPLACE({contr_actv.dept_id},'1' ,''),'2', ''), '3', '');
    You just have to build it up a little more so it caters for numbers 0 - 9.  At the moment it only works for numbers 1 - 3.  Another way you could do this is write some code to loop through the length of the string looking at each individual character to test for a number.
    I don't have time today to write something like that but the above should work as long as you don't have numbers in the middle of names etc.
    Cheers,
    Chris

  • HT1386 The first time I synced my iphone with my mac, I didn't realize that all of my photos from iphoto would transfer over to the phone.   Now, I need to remove some, as they are taking up too much space.  I cannot figure out how to remove them from the

    The first time I synced my iphone 4 with my mac, I didn't realize that all of my photos from the iphoto library would transfer over to the phone (more than 3,000).   Now, I need to remove some, as they are taking up too much space.  I cannot figure out how to remove them from the phone.  I tried to uncheck boxes and sync again, but I get a message that there is no room on the iphone.  I've read as many articles as I can find, but still cannot manage this.  Thanks for any help.

    Open itunes, connect iphone, select what you want, sync

  • Photoshop Elements 12 has been wiped of my laptop when they removed some viruses. How do I get it back because I bought it online and downloaded it instead of having the program disc?

    How do I recover the program for Photoshop Elements 12 that was wiped off my computer when they removed some viruses? I no longer have the program because I bought it on-line and downloaded it instead of having the program disc. I bought it last year and can't seem to contact anyone at Adobe or find out who to call.

    You can download it here:
    http://prodesigntools.com/photoshop-elements-12-direct-download-links-premiere.html
    Follow the Very Important Instructions exactly, even when they don't seem to make much sense. Of course you will need your serial number.

  • Maybe you are looking for

    • Error message without link to field

      I have a page where I am entering some information and saving it. I am using a VO which is based on an EO. I have two instance of this VO. One is being populated from the page and other one is being populated in the background. I have put some valida

    • [SOLVED]Problem with KDEmod

      Hi, I just installed KDEmod, everything seems to be running great except one thing.  When I open a program such as firefox or pidgin the window theme is not in sync with the KDE 4 theme.  Rather it looks more like a window from the Windows 95 days. 

    • I cant open my account

      hi my friend have account is i cant open it and i send request to refer my password and skype send me the new password to sign in by them but when i signing in the system write to me my user or password wrong ! also i use the new password sent from y

    • Have you ever had a play with an iPhone 4 then gone back to your 3G?

      Even with 3.1.3 installed you realise how slow the 3G is, everything is just instant on the iPhone 4, no lag at all, After having an iPhone 4 for a day I find it really frustrating using my 3G again.

    • Ready To Switch to Tiger

      Well, I have waited 2 years to do it but I think I am ready to buy and install Tiger. I am presently running Panther on a PB G4. I would like to have a tutorial on installing over Panther and some helpful hints on backing up my music from iTunes. Doe