str1=Replace("陈明(1)张史(1)周细林(1)","(1)","(2)",8,1)的结果应该是 "陈明(1)张史(2)周细林(1)",但是结果却是"(2)周细林(1)",真是有点不明白?
解决方案 »
- 急!请问如何在组件(dll)中使用ocx?能否提供详细的配置过程和代码!
- 如何利用VB程序或IE客户端动态创建虚拟串口
- 怎么样将16位bmp转换为32位,保持dpi不变。急!请高手帮忙!
- 请教各位大哥个关于vc转vb 的问题 那位大哥帮帮小弟
- 在VB6中有没有像vb工具箱的控件?
- 二进制存取为什么总说“类型不匹配”
- 关于WindowsXP的时间格式给我带来的困扰~~!Up有分!
- 使用vb的Winsock控件能实现内网与公网通信吗?请高手们指点迷津
- 选择问题..............在线等候
- 用ADO 将text中的数据读取到access中,存在问题
- 一小段延时程序
- 搞VB那么多年了,今天才发现不会多选文件....
起始页 | 版本 2
请参阅
--------------------------------------------------------------------------------描述
返回字符串,其中指定数目的某子字符串被替换为另一个子字符串。
语法
Replace(expression, find, replacewith[, compare[, count[, start]]])
Replace 函数的语法有以下参数:参数 描述
expression 必选。 字符串表达式 包含要替代的子字符串。
find 必选。被搜索的子字符串。
replacewith 必选。用于替换的子字符串。
start 可选。expression 中开始搜索子字符串的位置。如果省略,默认值为 1。在和count 关联时必须用
count 可选。执行子字符串替换的数目。如果省略,默认值为 -1,表示进行所有可能的替换。在和 start 关联时必须用。
compare 可选。指示在计算子字符串时使用的比较类型的数值。有关数值,请参阅“设置”部分。如果省略,缺省值为 0 ,这意味着必须进行二进制比较。
设置
compare 参数可以有以下值:
常数 值 描述
vbBinaryCompare 0 执行二进制比较。
vbTextCompare 1 执行文本比较。 返回值
Replace 返回以下值:
如果 Replace 返回
expression 为零长度 零长度字符串 ("")。
expression 为 Null 错误。
find 为零长度 expression 的副本。
replacewith 为零长度 expression 的副本,其中删除了所有由 find 参数指定的内容。
start > Len(expression) 零长度字符串。
count 为 0 expression 的副本。
说明
Replace 函数的返回值是经过替换(从由 start 指定的位置开始到 expression 字符串的结尾)后的字符串,而不是原始字符串从开始至结尾的副本。
下面的示例利用 Replace 函数返回字符串: Dim MyString'二进制比较从字符串左端开始。返回 "XXYXXPXXY"。
MyString = Replace("XXpXXPXXp", "p", "Y") '文本比较从第三个字符开始。返回 "YXXYXXY"。
MyString = Replace("XXpXXPXXp", "p", "Y", 3, -1, 1)
上面的说明已经指出这个问题,要是返回前面的,用left()函数截取一下前面的7个字符吧.
如果你想将字符串:"陈明(1)张史(1)周细林(1)",修改为:"陈明(1)张史(2)周细林(1)",最高方法是用mid语句:dim s as string
s="陈明(1)张史(1)周细林(1)"
mid(s,9,1)="2"
msgbox s
Replace("陈明(1)张史(1)周细林(1)","(1)","(2)", 8,1)
start 可选的。在表达式中子字符串搜索的开始位置。如果忽略,假定从1开始。 ”事实上要这么描述:“返回一个字符串,该字符串中指定的子字符串已被替换成另一子字符串,并且替换发生的次数也是指定的
start 可选的。在表达式中子字符串搜索的开始位置。如果忽略,假定从1开始。如果大于1,那么字符串中这个数前面的字符将被剔除。 ”
DescriptionReturns a string in which a specified substring has been replaced with another substring a specified number of times.SyntaxReplace(expression, find, replace[, start[, count[, compare]]])
The Replace function syntax has these named arguments:Part Description
expression Required. String expression containing substring to replace.
find Required. Substring being searched for.
replace Required. Replacement substring.
start Optional. Position within expression where substring search is to begin. If omitted, 1 is assumed.
count Optional. Number of substring substitutions to perform. If omitted, the default value is –1, which means make all possible substitutions.
compare Optional. Numeric value indicating the kind of comparison to use when evaluating substrings. See Settings section for values.
SettingsThe compare argument can have the following values:Constant Value Description
vbUseCompareOption –1 Performs a comparison using the setting of the Option Compare statement.
vbBinaryCompare 0 Performs a binary comparison.
vbTextCompare 1 Performs a textual comparison.
vbDatabaseCompare 2 Microsoft Access only. Performs a comparison based on information in your database.
Return ValuesReplace returns the following values:If Replace returns
expression is zero-length Zero-length string ("")
expression is Null An error.
find is zero-length Copy of expression.
replace is zero-length Copy of expression with all occurences of find removed.
start > Len(expression) Zero-length string.
count is 0 Copy of expression.
ResThe return value of the Replace function is a string, with substitutions made, that begins at the position specified by start and and concludes at the end of the expression string. It is not a copy of the original string from start to finish.--------------------------------------------------------------------------------
Send feedback to MSDN.Look here for MSDN Online resources.
replace常用,可是掌握的知识没有这么细.