How to repeatedly replace different strings with most chars are Not unique?

NOTE: I'm trying to avoid to do a substring of a substring of a ... replacement.
Hello there,
I'm looking for solution on a best approach to do a string replacment in something like example below.
The idea would be to:
1. Open a file and Find a "Title" (i.e. TC162-01.2GFC (after <td colspan=6>)). The Title here will be a dynamic and can be changed from one run to another.
2. If it match to expected value then do a replacement of data between <select... and </select> for another values.
3. Keep going for each block of <tr> ... </tr>
=======================================
<tr>
<td colspan=1>1</td>
<td colspan=1>TC1.1</td>
<td colspan=6>TC162-01.2GFC</td>
<td colspan=2>Unknown</td>
<td colspan=1><select name="res_1_0_20789_21522" size=1>
<option>PASS</option><option>FAIL</option><option selected>No Status</option></select> </td>
<td colspan=1><input type=text maxlength='30' size='10' name='comment_1' value=''></td></tr>
<tr>
<td colspan=1>2</td>
<td colspan=1>TC1.2</td>
<td colspan=6>TC162-01.3ABC</td>
<td colspan=2>Unknown</td>
<td colspan=1><select name="res_2_0_20790_21523" size=1>
<option selected>PASS</option><option>FAIL</option><option>No Status</option></select> </td>
<td colspan=1><input type=text maxlength='30' size='10' name='comment_2' value=''></td></tr>
=======================================

Here's a simple and conceptual example. You could use your real implementation of the getReplace() method.
/** file: test-vlad.txt *************************************
<tr>
<td colspan=1>1</td>
<td colspan=1>TC1.1</td>
<td colspan=6>TC162-01.2GFC</td>
<td colspan=2>Unknown</td>
<td colspan=1><select name="res_1_0_20789_21522" size=1>
<option>PASS</option><option>FAIL</option><option selected>No Status</option></select> </td>
<td colspan=1><input type=text maxlength='30' size='10' name='comment_1' value=''></td></tr>
<tr>
<td colspan=1>2</td>
<td colspan=1>TC1.2</td>
<td colspan=6>TC162-01.3ABC</td>
<td colspan=2>Unknown</td>
<td colspan=1><select name="res_2_0_20790_21523" size=1>
<option selected>PASS</option><option>FAIL</option><option>No Status</option></select> </td>
<td colspan=1><input type=text maxlength='30' size='10' name='comment_2' value=''></td></tr>
import java.util.regex.*;
import java.io.*;
public class Vlad{
  public static void main(String[] args) throws Exception{
    BufferedReader br;
    StringBuffer sb;
    String line, fcontent;
    sb = new StringBuffer();
    br = new BufferedReader(new FileReader("test-vlad.txt"));
    while ((line = br.readLine()) != null){
      sb.append(line + "\n");
    fcontent = sb.toString();
    String regex
     = "<td colspan=6>([^<]+)(</td>.+?<select[^>]+>)(.+?)</select>";
    Pattern pat = Pattern.compile(regex, Pattern.DOTALL);
    Matcher mat = pat.matcher(fcontent);
    StringBuffer rsb = new StringBuffer();
    while (mat.find()){
      String title = mat.group(1);
      String value = mat.group(3);
      String newValue = getReplace(title, value);
      mat.appendReplacement
        (rsb, "<td colspan=6>" + title + "$2" + newValue + "</select>");
    mat.appendTail(rsb);
    System.out.println(rsb.toString());
  } // end main()
  // a dummy implementation
  static String getReplace(String tdTitle, String selectValue){
    return "###ANOTHER VALUES###";
}Edited by: hiwa on Dec 11, 2007 11:14 AM

Similar Messages

  • How do I compress a string with  java.util.zip - not a file ?

    How do I compress a string with java.util.zip?
    Is possible to compress something else except a file?

    Of course, compression works on bytes, not some higher level constructs like Strings or files.
    You can use the ZipOutputStream or DeflaterOutputStream for compression.
    And the javadoc for Deflater even has a code example of compressing a String.
    Edited by: Kayaman on May 22, 2011 5:04 PM

  • Zip file with special chars are not unzipped properly

    Hi all,
    i have following problem: I want to unzip a zip file. In the zip file there is a file with a special character i.e. "straße". When i call now zipFile.getInputStream( entry ) null will be returned. What can i do? Thanks a lot
    ZipFile zipFile = new ZipFile( file );
        Enumeration enumeration = zipFile.entries();
        while ( enumeration.hasMoreElements() )
          ZipEntry entry = ( ZipEntry ) enumeration.nextElement();
          if ( !entry.isDirectory() )
            InputStream in = null;
            OutputStream out = null;
            try
              in = zipFile.getInputStream( entry );  //<- Here null will be returned When i look at the entry the "ß" of "straße" is represented by á.

    May be you need to specify an ecoding for ZipEntry that would allow special characters?

  • How do I replace the organiser with a new one

    How do I replace the organiser with a new one

    The problem is to understand your question (or your two questions : do you both mean the same thing ?)
    An answer to Hatstead question would help.
    1 - Do you really mean using another software to organize your workflow ?
    2 - Do you mean using other softwares based on folders rather than databases ?
    3 - Or do you mean working with different catalogs ?
    If you don't want to use the Organizer, it's not possible to 'delete' it, but it is simple not to use it.
    Most other organizing solutions include the choice of selecting PSE editor as the external editor
    There are various solutions depending on your platform : Windows, Mac, Linux...
    It's important to know if you prefer the folders or database organization to suggest possible solutions.

  • How do i replace my 5c with a 5 or 5s

    how do i replace my 5c with a 5 or 5s,  there is nothing out there for cases or anything to match the button layout on the phone,  i have spent $100 in 2 days buying case after case

    Returning the phone woudl be a serious hassle as both the 5 and the 5S are in short supply, one permanently and the other for who knows how long!
    They didn't have a lot of them, so, good luck.
    Best of luck.

  • How to export 2 different report with a link at the same time

    Hi,
    Do anybody know how to export 2 different report with a link at the same time. I currently create a report which link to another report. But when I want to export the 1st report I also want the 2nd report also be exported.
    Thank you very much.
    Best Rgds,
    SL Voon

    Export all the three components individually.
    It will generate 3 script files. Now run them from SQL>
    null

  • How to create dynamic connection string with variables using ssis.

    Hello,
    Can anyone let me know on how to create dynamic connection string with variables using ssis?
    Any help would be appreciated.

    Hi vinay9738,
    According to your description, you want to connect multiple database from multiple servers using dynamic connection.
    If in this case, we can create a Table in our local database (whatever DB we want) and load all the connection strings.  We can use Execute SQL Task to query all the connection strings and store the result-set in a variable of object type in SSIS package.
    Then use ForEach Loop container to shred the content of the object variable and iterate through each of the connection strings. And then Place an Execute SQL task inside ForEach Loop container with the SQL statements we have to run in all the DB instances. 
    For more details, please refer to the following blog:
    http://sql-developers.blogspot.kr/2010/07/dynamic-database-connection-using-ssis.html
    If there are any other questions, please feel free to let me know.
    Regards,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • Replace a string with another string in a file

    I have to replace a string with another string. Say for example in a html file it got a line like,
    <a href="##"></a>
    now i want to replace this ## with the full derived path like
    "c;\\sample folder\\sample subfolder\\samplefile.html"
    can someone help me to do this?
    pls tell me from the file opening till closing the file.

    I have to replace a string with another string. Say
    for example in a html file it got a line like,
    <a href="##"></a>
    now i want to replace this ## with the full derived
    path like
    "c;\\sample folder\\samplesubfolder\\samplefile.html"
    can someone help me to do this?
    pls tell me from the file opening till closing the
    file.
    public class Buckel {
      final static String CONST = "c:\\sample folder\\samplesubfolder\\samplefile.html";
      public Buckel() {
      public static void main ( String[] argv )  throws Exception {
        int    idx = 0;
        String in  = "<a href=\"##\"></a>",   // We'll imagine this just gets here somehow. If it's on the i/p file then take the '\' out B4 and aft the '##'.
               out = "";
        idx = in.indexOf( "##" );
        if ( idx > 0 ) {
          out = in.substring( 0, idx ) + CONST + in.substring( idx+=2, in.length() );
        System.out.println( out );
    }

  • How can i update my app with i tunes?not by my device.

    how can i update my app with i tunes?not by my device.

    Select Apps in iTunes sidebar. A list of all your apps should be displayed in the main window. At bottom right of the window is a Check for updates button. Click on it, then click to download the updated apps. It's also possible that iTunes checked for updatedin the background, in which case the check button will already display how many updates you have.

  • TS1398 how come my ipod wont update with an error saying not connected to internet when it is

    how come my ipod wont update with an error saying not connected to the internet when it is?

    Try disabling the computer's antivirus and firewall during the download and update.

  • Creating a view on KONA & KONH -  Failed with 'Field name DATAB not unique'

    Hi all,
        I am creating a view on KONA (Rebate Agreement) & KONH (Conditions Header) tables. The link is KONA-KNUMA = KONH-KNUMA_AG.
       The field 'DATAB' exists in both tables and I have included those two fields under 'View Fields' . When I tried to activate the View, it fails with 'Field name DATAB not unique'.
       The following is the complete error message:
    Message no. MC060
    Diagnosis
    When you define aggregates (views, lock objects or matchcode objects), you can assign the aggregate fields your own names (the system assigns names to the basic fields automatically). These names must be unique.
    System response
    The system has established that the names assigned to the aggregate fields in an aggregate definition are not unique and issues an error message.
    Procedure
    Assign unique names to the aggregate fields in question.
       Why I am not able to create the view after including a field that EXISTS in two tables, PLEASE ?
    Thanks,
    Venkat.

    Hi,
    you can include both fields (but what for??); most likely KNUMH will also complain after fixing DATAB (just a guess...).
    You can include both fields if you name them differently (different aliases):
    In the view fields tab, enter two different names in the column "view field".
    this will work.
    hope this helps...
    Olivier.
    Message was edited by:
            Olivier Cora

  • VS Exp 2013: Unable to create the Web site ... The components for communicating with FTP servers are not installed.

    I have MS Visual Studio Express 2013 It has worked fine for many months and then suddenly (I have made no configuration changes or added new programs) when I try to publish I am getting the message:
    Unable to create the Web site 'ftp://ftp.xx.xx/xxx.org.uk/www/htdocs'. The components for communicating with FTP servers are not installed.
    (I have replaced actual name with x's).
    I had a similar problem some months ago and found that saving all files, closing VS 2013 and re-starting the program fixed the problem. This time it has not.
    I am at a loss to know how to take this forwards. I do not use IIS.
    Any help would be appreciated.
    Michael.

    Hi Michael,
    For web site development, so you use the VS2013 express for web, am I right? We have to make sure that it is not the VS version issue.
    As you said that it worked well before, did you install other add-ins or tools in your VS IDE like
    Xamarin or others?
    Maybe you could disable or remove all add-ins in your VS IDE, test it again.
    please also install the VS2013 update 4 in your side.
    Best Regards,
    Jack
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Since changing our computer I have been unable to download ebooks to my Reader Library I get a message Some file types associated with EPUB files are not associated with Reader Library; Waterstones suggest that I may have accidentally created a new Adobe

    When I try to download them from the Waterstones website I get a message saying:
    ‘Some file types associated with EPUB files are not associated with Reader Library.  Do you want to associate them now?  When I reply yes I get another message; ‘Configuration error unable to update EPUB files check network firewall and try again’.
    The ‘books’ are saved in the Download directory and I can’t transfer them from there to my E-Reader. I have not had any problems before, it was very simple; I saved the download and it automatically went into the Reader Library.
    I contacted HP and they said it is a software error and suggested I contact Waterstones.  I contacted Waterstones Customer Support and got the following response:
    As the error message is specifically mentioning the firewall it does sound like something in the firewall settings is stopping the download from taking place correctly. However, the files should not be being saved to the Download folder. It would be worth trying again by going to your Digital Order History on your Waterstones.com account and pressing the download button, and then making sure to press "Open" not "Save". When you press Open rather than Save it should give the option to open the file with Adobe Digital Editions. If the firewall message still comes up then I'm afraid something is blocking it on your end.
    If the above "Open" download method works but you then still get an error message it could possibly be that you have accidentally created a new Adobe ID when setting up on the new computer, rather than signing in with your old Adobe ID. It would be worth trying the aforementioned download technique again first, but if problems did still persist it would be worth calling Adobe themselves on 0207 365 0735, as they should be able to sort out any account issue.
      In response to the first para of Waterstones email I already do what they suggest I do press ‘Open’ not ‘Save’ but I don’t get the open with Adobe Digital Editions (we have installed Adobe Digital Editions on the new computer. Waterstones say we may have ‘accidentally created a new Adobe ID when setting up the new computer’ does that mean that we shouldn’t have installed Adobe Digital Editions on the new computer as it would have already been there? How do I sign in with my old Adobe ID? 

    Hi all after attampting to get some supoport from adobe by phone.... nice people infurating policys as far as support for digital editions or DRM is conserned... However I got no where with support.
    I ended up instaling Digital editions on my desktop PC and going through the motions of registering and borrowing a book then returning it. Then I trying on my iPad, Bluefire worked, Over drive did not so I completely removed Overdrive and reinstalled and re registered. all working now.
    Maybe some one at adobe did something. Maybe the install of the adobe DE client on a PC corrected what ever was out of wack with my account. Mayby the server that my account lives on did a scan disk and corrected a bad clustrer.
    What ever happend My account is actiove and working again. hope this helps others.

  • How do i check the list of invoices which are not posted into sap.

    Hi All,
    Iam displaying(ALV) the list of invoices and epayments for both PO & non PO transactons which are being processed in workflow but not posted in sap.
    (Non po transaction is th eone with out reference of a PO)
    How to check and list out the invoices that are not posted in sap. where does this get stored.
    please help.
    Thanks
    jyothi.

    Hello Jyothi,
    U can give try with EKBE table for getting invoices for PO. In this table there is a field vgabe which has various status. U can try that. Now for Non PO, u would be directly creating invoice doucment using FB60(i guess) which would create an entry directly into BKPF/BSEG. U can scan BKPF for the date range company code document type KR which vendor invoice.

  • BBPGETVD - error:backend systems with release 700 are not supported

    Hi,
    When I am trying to replicate vendor data from EEC to crm 4.0 via BBPGETVD.
    I get the error message"backend systems with release 700 are not supported"
    Is anyone have Idea what is wrong? and how can fix it?
    Thanks,
    Rachel

    Yossi,
    I believe that standard transaction does not work with ECC 6.0.  The standard response would be to upgrade your CRM system to 5.0 so that you can download vendors from ECC 6.0.
    Bascially the vendor replication programs in CRM below 5.0 aren't really that reliable for delta downloads(one error will cause an entire load to fail).  So you probably at best should copy the SAP standards to generate custom load programs as a starting point.
    It is not too difficult and overcomes some of the restrictions that SAP puts in place(i.e. you can only use one number range for vendors downloaded, etc.).  This is definitely one of the weak points of CRM 4.0 that was fixed in CRM 5.0.
    If you have more questions on this let me know.
    Take care,
    Stephen

Maybe you are looking for

  • Deleting more than one e-mail at a time

    Is there a way to delete multiple e-mails at once? it takes an awful long time to delete them one at a time.

  • Can I keep my iTunes library solely on an external drive?

    I have the macbook air with 128gig HD. I currently have a Windows laptop with a bigger HD housing my itunes network with all of my music and digital copies of movies. I've been using this computer as my primary laptop since I bought it (love it too m

  • Having trouble using a vector from another class

    have a vector in an addresbook class but when I try to acess the vector to write its object to a file from a write class, it doesn't resolve the symbol for the variable. How to I use the same same vector across different classes. thanks

  • SQL query to get the details

    We have a database with machine details such as ID, Hostname, IP Address, OS, etc... ID IP Address Hostname Protocol NetMask 1 10.216.16.47 Test123 DNS 255.255.255.0 1 10.216.16.48 Test123 DNS 255.255.255.0 54 10.216.68.85 Test73711340 DNS 255.255.25

  • Missing movies in project since iOS 8 and iCloud Photo Library

    Hi, I've been to Europe this summer and created a movie in iMovie for iOS. That was when iOS 7.1.2 was the most current release. Today, I wanted to finish up my project. I'm currently running on iPad air, iOS 8.0.2, latest release of iMovie and iClou