Sybase Business Intelligence Solutions - Database Management, Data Warehousing Software, Mobile Enterprise Applications and Messaging
Sybase Brand Color Bar
delete

Search for    in all of Sybase.com
view all search results right arrow
  blank
 
 
 
 
 
 
 
 
 
 
Support > Technical Documents > Document Types > Technote > A String Occurrence Search and Replace Routine  
RSS Feed
 
 
 
A String Occurrence Search and Replace Routine (PowerBuilder 7, 8 and 9)


/*THIS ROUTINE WORKS GENERICALLY FOR ANY STRING. FOR EXAMPLE, IF OLD_STR = "red" AND NEW_STR = "green", ALL OCCURRENCES OF "red" INSIDE OF MYSTRING WILL BE REPLACED WITH "green".*/


long      ll_StartPos = 1
string    ls_old_str, ls_new_str, ls_txt_str

ls_txt_str = sle_1.Text
ls_old_str = "red"
ls_new_str = "green"

// Find the first occurrence of 
ls_old_str ...
ll_StartPos = Pos(ls_txt_str, ls_old_str, ll_StartPos)

// Only enter the loop if you find 
ls_old_str ...

DO WHILE ll_StartPos > 0
    // Replace old_str with 
ls_new_str ...
    ls_txt_str = Replace(ls_txt_str, ll_StartPos, Len(ls_old_str), ls_new_str)

    // Find the next occurrence of 
ls_old_str
    ll_StartPos = Pos(ls_txt_str, ls_old_str, ll_StartPos + Len(ls_old_str))
LOOP

sle_2.Text = ls_txt_str


 

DOCUMENT ATTRIBUTES
Last Revised: Apr 14, 2003
Product: PowerBuilder
Technical Topics: Application Development
  
Business or Technical: Technical
Content Id: 42022
Infotype: Technote
 
 
 

© Copyright 2014, Sybase Inc. - v 7.6 Home / Contact Us / Help / Jobs / Legal / Privacy / Code of Ethics