Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Replace inside memo field
Message
From
07/04/2019 13:52:14
 
 
To
07/04/2019 10:24:12
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01667999
Message ID:
01668000
Views:
136
This message has been marked as the solution to the initial question of the thread.
Likes (2)
>Hi,
>
>I've string like this
>
>y = [Datum proizvod<PR>nje:  <#nnnn PR#> aaa <#trt  pr#> <<DATUMPROIZVODNJE>>]
>
>
>I want to replace the "pr" (all PR,pr,Pr...) with eg "7777" only if that "pr" is not inside
>
><#>  or inside  <<>>
>
>
>variable "y" should look like:
>
>Datum 7777oizvod<7777>nje:  <#nnnn PR#> aaa <#trt  pr#> <<DATUMPROIZVODNJE>>
>
>
>I tried this, but it's not good, it's a problem
>
><#nnnn PR#> and <#trt  pr#>
>
>
> ... it's two words
>
>
>...
>x = y
>
>FOR i = 1 TO ALINES( laArray, x )
> y = laArray[i]
> ? y
> 
> IF ATC("PR",y)>0
>     n=OCCURS('PR', UPPER(y))   
>     yy=y
>     FOR ix=1 TO n
>             IF (INLIST(GETWORDNUM(yy,ix),"<<","<#"))
>                 loop
>             ENDIF
>            
>          yy= STRTRAN(yy,"PR","7777",1,1,3)
>     ENDFOR
>     ? yy
> ENDIF
>...
>
Vojislav,

See if this covers your requirements:
LOCAL Source AS String
LOCAL ReplaceFrom AS String
LOCAL ReplaceTo AS String

m.Source = "Datum proizvod<PR>nje:  <#nnnn PR#> aaa <#trt  pr#> <<DATUMPROIZVODNJE>>"

m.ReplaceFrom = "pr"
m.ReplaceTo = "7777"

LOCAL Target AS String
LOCAL ARRAY Segments(1)

LOCAL Segment AS String
LOCAL SegmentIndex AS Integer

m.Target = ""

FOR m.SegmentIndex = 1 TO ALINES(m.Segments, m.Source, 2 + 8 + 16, "<<", "<#", ">>", "#>")
	m.Segment = m.Segments(m.SegmentIndex)
	IF !(RIGHT(m.Segment, 2) == ">>" OR RIGHT(m.Segment, 2) == "#>")
		m.Segment = STRTRAN(m.Segment, m.ReplaceFrom, m.ReplaceTo, -1, -1, 1)
	ENDIF
	m.Target = m.Target + m.Segment
ENDFOR

? m.Source
? m.Target
----------------------------------
António Tavares Lopes
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform