Le 4 sept. 06 à 21:21 Soir, RBNUBE a écrit:

I have a very long string that contains multiple occurrences of a string I
would like to replace.


As an example:

AAAAAAAAAAAAAAAAAAAA111111BBBBBBBBBBBBBBBBB111111CCCCCCCCCCCCCCCCCCC11 1111DD
DDDDDDDDDDDDDDDD

Say I want to replace the second instance of the series of ones with a
series of twos. How would I go about doing this? This would seem to be
simple, but I am stumped.

A "logical" way would be something like that: (ignore the comments; they are not good english)

  dim b As Boolean 'Is true when an "1" has already been found.
  dim i As integer
  dim j As Integer
  dim k As Integer 'Count how many series of "1" have been encountered.
  dim s As String

s="AAAAAAAAAA11111BBBBBBBBBB11111CCCCCCCCCC11111DDDDDDDDDD11111EEEEEEEEE E"
  j=len(s)

  for i=1 to j 'Going for every character
    if mid(s,i,1)="1" then 'We have an "1"
      if not b then 'And it's the first one
k=k+1 'We count the index of the serie of ones (when k is 1, we are between "A" and "B", when k is 2, we are between "B" and "C", etc.)
        b=True 'This will ignore other "1" in the same serie.
      end if
if k=2 then 'In this example, we want to replace the 2nd serie of "1".
        s=Left(s,i-1)+"2"+Right(s,len(s)-i) 'So we do that
      end if
    Else 'We don't have (or don't have any longer) an "1"
if b then 'We had a "1" serie, just before. We have to watch for new serie.
        b=False
      end if
    end if
  Next
  MsgBox s_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to