Results 1 to 6 of 6
  1. #1
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Hatsukaichi, Hiroshima, Japan
    Posts
    904
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Replace character with number sequence

    Hello, is there any easy way to automatically find all @ characters in a text file and replace them with a numerical sequence eg:

    hello @
    hello @
    hello @

    becomes:

    hello 1
    hello 2
    hello 3

    Is it possible to do this with some kind of expression. I googled regular expressions but was totally overwhelmed by the information I got! I have notepad++ and Dreamweaver both of which are supposed to be able to use regular expressions but I've no idea what that might be.

    Thanks,

    Chris (Hunt)

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Replace character with number sequence

    I wouldn't know how to do this with regular expressions, but here is a way to do it in MS Word:

    - Open the text file in Word.
    - Select the first @.
    - Press Ctrl+F9.
    - Type SEQ followed by a space before the @ so that it looks like

    { SEQ @ }

    - Press F9 to hide the field codes. You should now see a 1.
    - Select the 1 and copy it (Ctrl+C).
    - Select Edit | Replace or press Ctrl+H.
    - Enter @ in the Find what box.
    - Type ^c in the Replace with box (this is the code for "what's on the clipboard").
    - Click Replace All.
    - Press Ctrl+A to select the entire document.
    - Press F9 to update the fields.
    - You should now see the sequence numbers.
    - Save the text file. Click Yes when Word warns that features might be lost.
    Note: don't save as a HTML file - this will add lots of junk that you don't want.

    Others may well come up with a more efficient method.

  3. #3
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Hatsukaichi, Hiroshima, Japan
    Posts
    904
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Replace character with number sequence

    Thanks Hans. I tried the method you suggested and it seemed to be working but the final F9 key press did nothing and I ended up with a lot of 1's rather than a sequence. Perhaps my Word is too old - I have Office 97. I ended up making the changes by hand. I had about 30 to do. It would be good to find a solution in case I need to do it again. I spent some time googling but couldn't find an answer.

    Chris

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Replace character with number sequence

    As far as I know, this should work in Word 97 too. Are you sure that you selected the entire document before pressing F9?

  5. #5
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Hatsukaichi, Hiroshima, Japan
    Posts
    904
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Replace character with number sequence

    Yes, just tried it again. used Ctrl + A to select all - but got the same result. Perhaps my word is missing some component or setting.

    Thanks,

    Chris

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Replace character with number sequence

    Does it make a difference if you change the first instance of @ to a field looking like this:
    <code>
    { SEQ "A" }
    </code>
    The rest of the procedure remains the same. Remember, the braces { } must be inserted by pressing Ctrl+F9.
    If that doesn't work either, you could use the following macro:

    Sub AddSequence()
    Dim n As Integer
    Application.ScreenUpdating = False
    Selection.HomeKey Unit:=wdStory
    With Selection.Find
    .ClearFormatting
    .Text = "@"
    .MatchWholeWord = False
    .MatchWildcards = False
    Do While .Execute
    n = n + 1
    Selection.Text = n
    Selection.Collapse Direction:=wdCollapseEnd
    Loop
    End With
    Application.ScreenUpdating = True
    End Sub

    I wrote this in Word 2002, I hope it works in Word 97.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •