|
Do you have source some source that you want to share? Is there some source that you want to see posted here? If so, Contact Us and we'll be more than happy to help. |
****************************************************************
* Description.. Replace Characters in a String *
* Program Name. F.REPLACE *
* Author....... Bradley V. Stone *
* BVS/Tools - www.bvstools.com *
****************************************************************
H NOMAIN
****************************************************************
* Prototypes *
****************************************************************
D #Replace PR 1024 Replace Characters
D InString 1024 VALUE
D From 56 VALUE
D To 56 VALUE
*//////////////////////////////////////////////////////////////*
* (#Replace) Replace character(s) with new character(s) *
* *
* Use: #Replace(String : replace_this : with_this) *
* *
*//////////////////////////////////////////////////////////////*
P #Replace B EXPORT
*--------------------------------------------------------------*
D #Replace PI 1024
D InString 1024 VALUE
D From 56 VALUE
D To 56 VALUE
*
D String S 1024
D Temp S 1024
D i S 4 0
D j S 4 0
D len S 4 0
D lenTo S 4 0
*--------------------------------------------------------------*
C eval String = InString
C eval i = 1
C ' ' CHECKR From len 99
*
C if (not *IN99)
C eval len = %size(From)
C endif
*
C ' ' CHECKR To lenTo 99
*
C if (not *IN99)
C eval lenTo = %size(To)
C endif
*
C From:len SCAN String:i j
*
C dow (j <> 0)
C eval Temp = %trim(To) + %subst(String:j+len)
*
C if (j = 1)
C eval String = Temp
C else
C eval String = %subst(String:1:j-1) + Temp
C endif
*
C eval i = (j + lenTo)
C From:len SCAN String:i j
C enddo
*
C RETURN String
*--------------------------------------------------------------*
C *PSSR BEGSR
C RETURN InString
C ENDSR
*--------------------------------------------------------------*
P #Replace E
|