Merging text files along with their filename

I am looking to merge a whole bunch of text files into one document. I am going to the Insert tab and selecting the drop down menu in Object to select text from file.  All of the text is merging in the one document correctly, but I am not
getting the title/file name of the document inserted in the document and I would like that to be in there. Is there a way of doing this?

Try the following macro. It assumes you're working with doc, docx & docm files. If not, change the 'doc' in the '*.doc' reference to whatever file type you're working with.
Option Explicit
Public oFolder As Object 'the folder object
Public i As Long, j As Long
Public DocTgt As Document
Sub Main()
' Minimise screen flickering
Application.ScreenUpdating = False
Dim StrFolder As String
' Browse for the starting folder
StrFolder = GetTopFolder
If StrFolder = "" Then Exit Sub
' Initialize the counters
i = 0: j = 0
Set DocTgt = ActiveDocument
' Search the top-level folder
Call GetFolder(StrFolder & "\")
' Return control of status bar to Word
Application.StatusBar = ""
' Restore screen updating
Application.ScreenUpdating = True
MsgBox i & " of " & j & " files processed.", vbOKOnly
End Sub
Function GetTopFolder() As String
GetTopFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetTopFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function
Sub GetFolder(StrFolder As String)
Dim strFile As String
strFile = Dir(StrFolder & "*.doc")
' Process the files in the folder
While strFile <> ""
  ' Update the status bar is just to let us know where we are
  Application.StatusBar = StrFolder & strFile
  Call UpdateFile(StrFolder & strFile)
  strFile = Dir()
Wend
End Sub
Sub UpdateFile(strDoc As String)
Dim Doc As Document
' Open the document
Set Doc = Documents.Open(strDoc, AddToRecentFiles:=False, ReadOnly:=False, Format:=wdOpenFormatAuto, Visible:=False)
With Doc
  If .ProtectionType = wdNoProtection Then
  With .Range.Sections
    With .First.Footers(wdHeaderFooterPrimary).Range
      .InsertBefore Doc.Name & vbCr
      While .Characters.Last.Previous = vbCr
        .Characters.Last.Previous = vbNullString
      Wend
    End With
    .Add Start:=wdSectionBreakNextPage
  End With
  DocTgt.Characters.Last.FormattedText = .Range.FormattedText
    ' Update the file counter for processed files
    i = i + 1
  End If
  ' Update the main file counter
  j = j + 1
  .Close SaveChanges:=False
End With
' Let Word do its housekeeping
DoEvents
Set Doc = Nothing
End Sub
With this code, each merged file's name will be added to its footer.
Cheers
Paul Edstein
[MS MVP - Word]

Similar Messages

  • I had a drive failure and lost the iWeb file along with other things.   I did manage to save a lot of user file documents but I don't see or   recognize the my iWeb site file. It was on a 15" G4 Titanium pb. I'm trying to find a way, using version 2.0.4

    I had a drive failure and lost the iWeb file along with other things. 
    I did manage to save a lot of user file documents but I don't see or 
    recognize the iWeb site file. It was on a 15" G4 Titanium pb.
    I'm trying to find a way, using version 2.0.4 of iWeb on a different 
    pb to recover the file into the iWeb app or a way to download the site into iWeb.
    There are 6 pages of images and text, and it 
    would be a task for me to recreate the whole thing again. I did 
    download the site but I don't know how or if I can get iWeb to see it and open it.
    Does anyone have any knowledge about this? The link to my site:
    <http://web.mac.com/danauerbach>
    Any suggestions will be most appreciated.
    dan auerbach
    [email protected]

    Unfortunately iWeb cannot read or import previously published files, only generate them.  You'll have to recreate your site from scratch.
    However, Chapter 2.3 on the iWeb FAQ.org site has tips on using some of the existing files, image, audio, video, etc., from the published site in the recreation of the site.
    OT

  • Is it possible to export full PCD object list along with their PCD ID?

    Hi
    Is it possible to export full PCD object list along with their PCD ID to an excel sheet or txt file?
    Any help will be appreciated.
    Regards
    Vineet

    Hi,
    I have provided a simple method below to Get all the PCD objects PCD  ID.
    1. Create a transport package.
    2. Add all the PCD objects for which ever you need the PCD ID.
    3. Now release the Transport package as the "File system" mode.
    4. Once it is done successfully, it will display all the transported object and its corresponding PCD ID in a table format.
    You can simply copy and paste it in a excel to get the PCD ID for the PCD objects.
    Hope this is helpful.
    Thanks,
    Mahendran B.

  • Extraction of Contexts along with their joins in Designer

    Post Author: sachinj
    CA Forum: Deployment
    Hi All,
    In designer, how can one extract the context along with it's relevant joins ?
    I tried File>Save As>Save as type changed to pdf. But the pdf does not give the contexts along with their respective joins.
    Does any one have solution to this one ..Thanx in advance.
    With Regards
    Sachin

    Hi,
    youa can use these two datasources:
    2LIS_11_VAKON                  Sales Document Condition     
    2LIS_13_VDKON                  Billing Document Condition   
    hope this helps...
    Olivier.

  • How to retrieve all the users along with their password from LDAP

    Hello,
    Can anyone let me know how to retrieve and list all the user along with their password from LDAP.
    Thanks

    Hi Prashant,
    I have limited experience with Synchronization, but I agree with you - if you need to synchronize Passwords, you need to have the Password in clear Text.
    If you trying to build your own Synchronization Solution using any of the avaliable LDAP APIs, I don't think you can ever retrieve a user's Password in clear text.
    However, I did come across an interesting article & I hope you find it useful :-
    http://www.oracle.com/technology/obe/obe_as_10g/im/configssl/configssl.htm
    I am not sure if SSL is necessary - If you have a look at Metalink Note 277382.1 ( How to Configure OID External Authentication Plug-In for Authentication Via Microsoft Active Directory (MS AD) ), teh question asked by oidspadi.sh for the same is asnwered as "N".
    Regards,
    Sandeep

  • Copying tables along with their indexes between databases

    I use sql server management studio express.  I have a database that has some questionable schemas, roles, etc, so I decided to create a new database, with just tables, stored procedures, and user-functions.
    So I used the "import data" feature, which allowed me to select several tables, that were copied along with their data.
    Then, I scripted out all the user-functions and stored procedures from the original database, and pasted them into a query window for the new database, and executed the create statements for each.
    Then I got a message that I was lacking a full-text index.
    I then started examining some tables, and even regular tables with an integer primary key that is supposed to be an identity' field were not identity fields any more, and lacked the auto-increment.
    I tried to change that, and make them auto-increment, and then sql server told me that I can't do that.  I guess if there is already data inside an integer field, you can't make it auto-increment.
    So how do I solve all this?
    Thanks

    You cant modify a column to be of type identity. For that you need to do the below
    http://www.mssqltips.com/sqlservertip/1397/add-or-drop-identity-property-for-an-existing-sql-server-column/
    But in your case what works best would be to script out the table along with identity and then use it to create the table in the new database.
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • How do i add a an editable text area along with a basic shape?

    hiee
    Thank u guys for replying to my previous query.I got the solution.
    Now ,my problem is, whenever i am drawing a new shape on the panel i want to add an editable text area along with the shape so that the shape can be given a userdefined name(something like Rational Ross).
    I am using g.drawString() but with that i can only add a static string.
    How can i add a JTextField or JTextArea along with the shape??
    Thanking u guys in advance.
    anvesha.

    It is considered standard procedure to acknowledge people's replies in the corresponding thread.
    As for your current problem, you'll have to make sure that the component you're subclassing is at least a Container. A JPanel could be a good pick. Set the layoutManager to null. Add your JTextField to your JPanel and use myTextField.setBounds(x, y, width, height) to place it whereever you want.

  • Import WSDL file along with XSD

    Hi,
    I have a WSDL file which has complex Data types (abc.wsdl). This complex data types are defined in the XSD file (abc-data.xsd).
    If I just import WSDL file in ED I am unable to find the Complex Data types in Message Mapping.
    How can I use the XSD file along with the WSDL file? Is there any source path as to give or what?
    Could you please help me out…?

    first i will tell how my wsdl file is defined
    <xs:element name="authInfo" type="<b>xx:AuthInfo</b>">                                   <xs:annotation>                              <xs:documentation xml:lang="en">                                   Authentication information                         </xs:documentation>                    </xs:annotation>                              </xs:element>
    and in my xsd file for xx:AuthInfo
    <xs:complexType name="AuthInfo">
              <xs:sequence>
                   <xs:element name="acctName" type="tns:CustName">
                        <xs:annotation>
                             <xs:documentation xml:lang="en">
                             account name.
                        </xs:documentation>
                        </xs:annotation>
                   </xs:element>
                   <xs:element name="password" type="tns:AcctPswd">
                        <xs:annotation>
                             <xs:documentation xml:lang="en">
                            Specify the password                    </xs:documentation>
                        </xs:annotation>
                   </xs:element>
              </xs:sequence>
         </xs:complexType>
    when i import wsdl file in Ed i will get two inputs there but only one as "AuthInfo"
    but "AuthInfo" has two inputs.
    this is how my Target Message Look like
    Tree          Occurences          Type
    authInfo     1..1                      xx:AuthInfo
    i hope i have cleared u..

  • To Import XSD file along with WSDL file in ED

    Dear All,
    I am doing a scenario web service1 —XI—RFC—web service2. Web service1 sends request to XI and XI sends to RFC and RFC response to web service2 and web service2 response (acknowledge) back to XI and XI sends back to web service1.
    My client (web service2) has given me the web service (WSDL) file along with XSD file.
    In the wsdl file there are number of elements and complex types.
    <xs:element name="GetCustomer">
         <xs:complexType>
              <xs:sequence>
                   <xs:element name="authentication" type="xx:AuthInfo"/>
                   <xs:element name="CompanyName" type=" xx:AuthInfo "/>
              </xs:sequence>
         </xs:complexType>
    </xs:element>
    The type (xx:AuthInfo and xx:AuthInfo) are defined in XSD file.
    My questions are
    1)     Do I have to import the XSD file in ED or not.
    2)     How do I map this XSD
    3)     As WS1, RFC and WS2 all are synchronous MT do I have to use BPM for it.
    4)     Can some one help with any docs please..
    Thanks in advance

    Hi,
    >>Do I have to import the XSD file in ED or not
    If you are having the wSDL files then you can take the structure from there itself. Just import the wsdl files in IR. You can also use XSD.
    >>How do I map this XSD
    XSD are same as Message Types. So create a MM and choose your XSD.
    >>As WS1, RFC and WS2 all are synchronous MT do I have to use BPM for it.
    Yes you have to because you are taking the responce from RFC and going to give it to WS2.
    BPM steps:
    1) receive (open sync bridge)
    2) transformation 1
    3) send (snyc)
    4)transformation 2
    3) send (close sync bridge)
    https://weblogs.sdn.sap.com/pub/wlg/1403 [original link is broken] [original link is broken] [original link is broken] [original link is broken]
    Regards
    Suraj

  • FM to down load the spool to excel file  along with the deliminator

    hi all,
    this is regarding a downloading of spool to a excel file along with a deliminator.
    Can any one suggest a function module which downloads spool to excel file with a deliminator in a proper way.

    Hi ram,
    You can try using the BAPI_XBP_JOB_SPOOLLIST_READ_20 - to get the list from spool and then do the required formatting. You can use can use the function module mentioned in the other reply to download it into excel file.
    Cheers

  • Merge text file with condition

    I have two text files (report1.txt and report2.txt) that I want to merge with conditions:
     - Matching rows that have same "ID" and same "TranVal", will keep only one instance
     - Mismatching rows that have same "ID" both rows from 2 file, but column "TranVal" has different value, then the row from report2.txt will replace row in report1.txt
     - Any "ID" that exists in one textfile but not the other one, will be copied to the final merged file
    report1.txt:
    TranDate,ID,TranVal,Comment
    061211,9840,40,done
    061211,9841,30,done
    061211,9842,28,done
    report2.txt:
    TranDate,ID,TranVal,Comment
    061211,9840,40,done
    061211,9841,89,done
    061211,9843,25,done
    Final result should be:
    merge.txt:
    TranDate,ID,TranVal,Comment
    061211,9840,40,done
    061211,9841,89,done
    061211,9842,28,done
    061211,9843,25,done

    Hi,
    I just checked Import-Csv option. I will be able to manage this problem if i can get it in CSV format and work with objects, BUT the problem is in my real file
    the file-format is different which is not comma-separated, instead have "-" as seperator. To simplify the problem i used comma in my question.
    TranDate,ID,TranVal,Comment
    061211-9840-40-done
    Could
    you suggest me if there is any way to convert "-" separators to CSV?

  • How to merge text files and put the result in a text file.

    Hi,
    I am trying to merge the files(text) using OWB and I would like to put the result in a file. Could any one please explain how to do this.
    Thanks and regards
    Gowtham Sen.

    using the unix commnad 'cat' along with the redirect '>>' will concat the files into one target
    #this will create the target file and over-write it if it existed already
    cat file1 > target
    ##Now add the rest of the files to the target, without over-writing
    cat file2 >>target
    cat file3 >>target
    cat file16 >> target
    You can then use an external table on the target file.
    A nicer way would be to user a 'for loop', but this will work fine.

  • How do I get my merged clips to reconnect with their audio?

    I am on FCP 7 syncing audio and video with ProRes 4444 @ 23.98. I am merging clips into bins labeled according to their scene. Pretty straight forward.
    We then decided to go to ProRes 422 proxy to edit on a smaller faster drive at a lower cost. I transcoded the footage to 422 proxy with MPEG Streamclip same frame rate, same dimensions 1920x1080.
    Next I go to relink the footage. Audio relinks and gives me this message: (Keep in mind these are copy and pasted files on the new hard drive).
    "Some attributes of one or more of the files you have chosen do not match the attributes of the original.... The attributes that differed are as follows:
    - Media start and end
    Would you like to try to reconnect them again?"
    Video relinks and gives me the same message, but adds "reel" as another attribute.
    I've seen these messages before and nothing has come of it so I didn't think anything of it at first. Checking all the individual audio and video clips. Everything is playing fine.
    THEN I go to play my merged clips... no audio!? Double click a merged clip in the browser, clip plays in the viewer but NO AUDIO. Right click on the merged clip file, select Item Properties and format. It is recognizing the correct audio clip that should be playing in the info there. I drag the clip into the timeline and I can see the shadow of the audio and video clip but when I let go in the timeline only the video appears.
    How can this be?? What am I missing??
    I would be so grateful for any ideas you might have!

    What happens if you control click on the audio clip in the timeline and choose "reveal in finder?"

  • GUI_UPLOAD not working for text file upload with '|' as a saperater

    Dear all,
    I have used 'GUI_UPLOAD' to upload data from text file having below format,
    1000|HBK1|HKTI
    1000|HBK2|HKTI
    1000|HBK3|HKTI
    My code is as below
    *& Report  ZTEST_NEW1
    REPORT  ZTEST_NEW1.
    TYPE-POOLS: truxs,
                kcde.
    TYPES :     BEGIN     OF             ty_data2          ,
                zbukr     TYPE           payr-zbukr       ,
                hbkid     TYPE           payr-hbkid       ,
                hktid     TYPE           payr-hktid       ,
               END       OF             ty_data2         .
    DATA :            it_file   TYPE           filetable        .
    DATA :      wa_file   LIKE LINE OF   it_file          .
    DATA :      w_rc      TYPE           i                ,
                lv_file   TYPE           string           .
    DATA : it_data2 TYPE TABLE OF ty_data2,
           wa_data2 LIKE LINE OF it_data2.
    SELECTION-SCREEN BEGIN OF BLOCK bk1 WITH FRAME TITLE text-020.
    PARAMETER : pr_file   TYPE           rlgrap-filename         .
    SELECTION-SCREEN END OF BLOCK bk1                            .
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR pr_file.
      PERFORM get_file.
    START-OF-SELECTION.
      PERFORM get_data.
    FORM get_file .
    CALL METHOD cl_gui_frontend_services=>file_open_dialog
    *  EXPORTING
    *    WINDOW_TITLE            =
    *    DEFAULT_EXTENSION       =
    *    DEFAULT_FILENAME        =
    *    FILE_FILTER             =
    *    INITIAL_DIRECTORY       =
    *    MULTISELECTION          =
    *    WITH_ENCODING           =
        CHANGING
          file_table              = it_file
          rc                      = w_rc
    *    USER_ACTION             =
    *    FILE_ENCODING           =
       EXCEPTIONS
         file_open_dialog_failed = 1
         cntl_error              = 2
         error_no_gui            = 3
         not_supported_by_gui    = 4
         OTHERS                  = 5
      IF sy-subrc EQ 0.
        CLEAR : wa_file.
        LOOP AT it_file INTO wa_file.
          pr_file = wa_file-filename.
          CLEAR : wa_file.
        ENDLOOP.
      ELSE.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                   WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    ENDFORM.                    " get_file
    FORM get_data .
    IF pr_file IS INITIAL.
        MESSAGE 'Enter file name'(002) TYPE 'E'.
      ENDIF.
      IF pr_file CP '*.xls'
        or pr_file CP '*.xlsx' . " Added
      ELSEIF pr_file CP '*.txt'.
    CONSTANTS : c_del TYPE c LENGTH 1 VALUE '|'.
        lv_file = pr_file.
    CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
        FILENAME                      = lv_file
       FILETYPE                      = 'ASC'
       HAS_FIELD_SEPARATOR           = c_del
    *   HEADER_LENGTH                 = 1
    *   READ_BY_LINE                  = 'X'
    *   DAT_MODE                      = ' '
    *   CODEPAGE                      = ' '
    *   IGNORE_CERR                   = ABAP_TRUE
    *   REPLACEMENT                   = '#'
    *   CHECK_BOM                     = ' '
    *   VIRUS_SCAN_PROFILE            =
    * IMPORTING
    *   FILELENGTH                    =
    *   HEADER                        =
      TABLES
        DATA_TAB                      = it_data2
    * EXCEPTIONS
    *   FILE_OPEN_ERROR               = 1
    *   FILE_READ_ERROR               = 2
    *   NO_BATCH                      = 3
    *   GUI_REFUSE_FILETRANSFER       = 4
    *   INVALID_TYPE                  = 5
    *   NO_AUTHORITY                  = 6
    *   UNKNOWN_ERROR                 = 7
    *   BAD_DATA_FORMAT               = 8
    *   HEADER_NOT_ALLOWED            = 9
    *   SEPARATOR_NOT_ALLOWED         = 10
    *   HEADER_TOO_LONG               = 11
    *   UNKNOWN_DP_ERROR              = 12
    *   ACCESS_DENIED                 = 13
    *   DP_OUT_OF_MEMORY              = 14
    *   DISK_FULL                     = 15
    *   DP_TIMEOUT                    = 16
    *   OTHERS                        = 17
    IF SY-SUBRC <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    endif.
    ENDFORM.                    " get_data
    In my output I am only getting company codes and not getting other two columns, can any body guide me where I am doing wrong?
    I have checked many other same kind of threads and I have done the same as suggested to do but still I am facing issue.
    Thanks in advance.
    Regards,
    Umang

    Hi Umang,
    There is a simple solution to this problem. Make the following changes to your code(marked in red color):
    REPORT  ZTEST_NEW1.
    TYPE-POOLS: truxs,
                kcde.
    TYPES :     BEGIN     OF             ty_data2          ,
                zbukr     TYPE           payr-zbukr       ,
                hbkid     TYPE           payr-hbkid       ,
                hktid     TYPE           payr-hktid       ,
               END       OF             ty_data2         .
    types: begin of ty_data
                 str type char200,
               end of ty_data.
    DATA: it_data type table of ty_data,
               wa_data type ty_data.
    DATA :            it_file   TYPE           filetable        .
    DATA :      wa_file   LIKE LINE OF   it_file          .
    DATA :      w_rc      TYPE           i                ,
                lv_file   TYPE           string           .
    DATA : it_data2 TYPE TABLE OF ty_data2,
           wa_data2 LIKE LINE OF it_data2.
    rest of the code **
    FORM get_data .
    IF pr_file IS INITIAL.
        MESSAGE 'Enter file name'(002) TYPE 'E'.
      ENDIF.
      IF pr_file CP '*.xls'
        or pr_file CP '*.xlsx' . " Added
      ELSEIF pr_file CP '*.txt'.
    CONSTANTS : c_del TYPE c LENGTH 1 VALUE '|'.
        lv_file = pr_file.
    CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
        FILENAME                      = lv_file
       FILETYPE                      = 'ASC'
    *HAS_FIELD_SEPARATOR           = c_del                    "comment this line
    HEADER_LENGTH                 = 1
      READ_BY_LINE                  = 'X'
      DAT_MODE                      = ' '
      CODEPAGE                      = ' '
      IGNORE_CERR                   = ABAP_TRUE
      REPLACEMENT                   = '#'
      CHECK_BOM                     = ' '
      VIRUS_SCAN_PROFILE            =
    IMPORTING
      FILELENGTH                    =
      HEADER                        =
      TABLES
        DATA_TAB                      = it_data
    EXCEPTIONS
      FILE_OPEN_ERROR               = 1
      FILE_READ_ERROR               = 2
      NO_BATCH                      = 3
      GUI_REFUSE_FILETRANSFER       = 4
      INVALID_TYPE                  = 5
      NO_AUTHORITY                  = 6
      UNKNOWN_ERROR                 = 7
      BAD_DATA_FORMAT               = 8
      HEADER_NOT_ALLOWED            = 9
      SEPARATOR_NOT_ALLOWED         = 10
      HEADER_TOO_LONG               = 11
      UNKNOWN_DP_ERROR              = 12
      ACCESS_DENIED                 = 13
      DP_OUT_OF_MEMORY              = 14
      DISK_FULL                     = 15
      DP_TIMEOUT                    = 16
      OTHERS                        = 17
    IF SY-SUBRC  0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    endif.
    Loop at it_data into wa_data.
    split wa_data-str at '|' into wa_data2-zbukr wa_data2-hbkid wa_data2-hktid.
    append wa_data2 to it_data2.
    clear wa_data2.
    Endloop.
    ENDFORM.                    " get_data
    IT_DATA2 will contain the final uploaded data. Hope this helps

  • Merge text files

    Hey all,
    I've got two text files that need to be merged into another text file. One is a template where I have to insert various things, and one is list of the things I have to insert. I am familiar with BufferedReader and PrintWriter etc but was wondering on some tips on how to do it.
    eg in the template.txt
    I have
    <<name>> <<address>>
    Welcome, <<name>>, you live at <<addresss>>.
    in the list.txt I have the name and address with delimiters which I believe you use Tokenizer for.
    i have
    Peter%n%
    60 Black Road%a&
    What is the order of things to process this and merge data in another text file?
    Thanks for help.

    Hi,
    Here comes a complete example, but it differs from the approach ChuckBing gave you. I think this is more generic, has speed advantages, and is easier to adapt/maintain to other situations.
    import java.util.HashMap;
    import java.util.Map;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    class Test {
        public static void main(String[] args) throws Exception {
            //Setup the generator
            //You want to read template from a file.       
            String template = "Welcome, <<name>>, you live at <<addresss>>"; 
            MessageGenerator generator = new MessageGenerator(template, "<<.*?>>");
            Record record = new Record();
            //Register callbacks for all tokens that you are interested in.
            generator.registerCallback("<<name>>", new AbstractCallback(record) {
                public String getValue(String token) {
                    return record.getName();
            generator.registerCallback("<<addresss>>", new AbstractCallback(record) {
                public String getValue(String token) {
                    return record.getAddress();
            //And test it.. You probably want to change this to a loop that
            //reads records, and writes the result to a file.
            record.setData("Kaj Bjurman%Any adress 21%");
            System.out.println(generator.getResult());
            record.setData("Another name%Another adress%");
            System.out.println(generator.getResult());
    * Generates messages using a template, and callbacks
    * @author Kaj Bjurman
    class MessageGenerator {
        private String template;
        private Pattern pattern;
        private int previousMatchIndex;
        private Matcher matcher;
        private Map callbacks;   // Map<String token, Callback callback>
        private StringBuffer result;
        public MessageGenerator(String template, String tokenPattern) {
            this.template = template;
            this.pattern = Pattern.compile(tokenPattern);
            callbacks = new HashMap();
        public void reset() {
            previousMatchIndex = 0;
            matcher = pattern.matcher(template);
            result = new StringBuffer();
        public void registerCallback(String token, Callback callback) {
            callbacks.put(token, callback);
        public String getResult() {
            reset();
            while (matcher.find()) {
                result.append(template.substring(previousMatchIndex, matcher.start()));
                previousMatchIndex = matcher.end();
                String token = matcher.group();
                Callback callback = (Callback)callbacks.get(token);
                String value = token;
                if (callback != null) {
                    value = callback.getValue(token);
                result.append(value);
            result.append(template.substring(previousMatchIndex));
            return result.toString();
        public static interface Callback {
            String getValue(String token);
    * Class that represents a record of data.
    * The data is expected to be in the form field1%field2%
    * @author Kaj Bjurman
    class Record {
        private String name;
        private String address;
        public void setData(String data) {
            String[] tmp = data.split("%");
            name = tmp[0];
            address = tmp[1];
        public String getName() {
            return name;
        public String getAddress() {
            return address;
    * @author Kaj Bjurman
    abstract class AbstractCallback implements MessageGenerator.Callback {
        protected Record record;
        public AbstractCallback(Record record) {
            this.record = record;
    }/Kaj

Maybe you are looking for

  • Questions on the Tungsten C

    I am a new owner of Tungsten C.  More of a Gearhead than a Techie.  So far it works great and does all that I want, still learning the nuances of the machine.  Hope this is posted in the right area, but I have a couple if questions. The SD slot does

  • Need help in sql plus

    i install in my computer the oracle9i my problem is that : i can login to sql plus althoge i was tring all the passwords that i know scott/tiger sys/change_on_install system/manager and the result is allways the same ora-12560 error how can i solve t

  • Photo Stream Image Size to iPad

    Is there a way to set the image size dementions that are uploaded via Photo Stream to iPad?

  • Can a 488.2 controller be used with 488.1 device?

    I was wondering if a 488.2 controller can be used with a 488.1 device? I have used the same controller with 488.2 devices with no problems but not with a 488.1 device.

  • Pairing iPhone with MacBook on FIOS network

    We recently got FIOS in our apartment. I have no problem connecting to our FIOS network on my MacBook via Airport or on my iPhone. However, I cannot get my iphone and MacBook to pair via FIOS. I recently had everything wiped off my MacBook and restor