pb中有現成的函式把字串中的特定字符替換嗎??
如把ADFGJIDFLOJDF中DF換成QW后變成AQWGJIQWLOJQW
還是要自己寫函式的??
1、如果有的話,請寫出函式的具體用法
2、如果沒有的話,請給出函式的具體寫法
請大俠們幫幫忙!!!
uj5u.com熱心網友回復:
replacereplacew
replacea
PB聯機幫助里都有
Description
Replaces a portion of one string with another.
Syntax
Replace ( string1, start, n, string2 )
Argument Description
string1 The string in which you want to replace characters with string2.
start A long whose value is the number of the first character you want replaced. (The first character in the string is number 1.)
n A long whose value is the number of characters you want to replace.
string2 The string that will replace characters in string1. The number of characters in string2 can be greater than, equal to, or less than the number of characters you are replacing.
Return value
String. Returns the string with the characters replaced if it succeeds and the empty string if it fails. If any argument's value is null, Replace returns
null.
Usage
If the start position is beyond the end of the string, Replace appends string2 to string1. If there are fewer characters after the start position than specified in n, Replace replaces all the characters to the right of character start.
If n is zero, then, in effect, Replace inserts string2 into string1.
uj5u.com熱心網友回復:
pfc有//////////////////////////////////////////////////////////////////////////// //
//
// Function: of_GlobalReplace
//
// Access: public
//
// Arguments:
// as_Source The string being searched.
// as_Old The old string being replaced.
// as_New The new string.
// ab_IgnoreCase A boolean stating to ignore case sensitivity.
//
// Returns: string
// as_Source with all occurrences of as_Old replaced with as_New.
// If any argument's value is NULL, function returns NULL.
//
// Description: Replace all occurrences of one string inside another with
// a new string.
//
//////////////////////////////////////////////////////////////////////////////
//
// Revision History
//
// Version
// 5.0 Initial version
//
//////////////////////////////////////////////////////////////////////////////
//
// Copyright ?1996-1997 Sybase, Inc. and its subsidiaries. All rights reserved.
// Any distribution of the PowerBuilder Foundation Classes (PFC)
// source code by other than Sybase, Inc. and its subsidiaries is prohibited.
//
//////////////////////////////////////////////////////////////////////////////
Long ll_Start
Long ll_OldLen
Long ll_NewLen
String ls_Source
//Check parameters
IF IsNull(as_source) Or IsNull(as_old) Or IsNull(as_new) Or IsNull(ab_ignorecase) THEN
String ls_null
SetNull(ls_null)
RETURN ls_null
END IF
//Get the string lenghts
ll_OldLen = Len(as_old)
ll_NewLen = Len(as_new)
//Should function respect case.
IF ab_ignorecase THEN
as_old = Lower(as_old)
ls_Source = Lower(as_source)
ELSE
ls_Source = as_source
END IF
//Search for the first occurrence of as_Old
ll_Start = Pos(ls_Source, as_old)
DO WHILE ll_Start > 0
// replace as_Old with as_New
as_source = Replace(as_source, ll_Start, ll_OldLen, as_new)
//Should function respect case.
IF ab_ignorecase THEN
ls_Source = Lower(as_source)
ELSE
ls_Source = as_source
END IF
// find the next occurrence of as_Old
ll_Start = Pos(ls_Source, as_old, (ll_Start + ll_NewLen))
LOOP
RETURN as_source
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/96433.html
標籤:腳本語言
