-->
![Vb6 String Replace Vb6 String Replace](http://www.vbforums.com/attachment.php?attachmentid=136669&d=1459627844)
See also ![Replace Replace](/uploads/1/2/5/7/125715705/533942483.JPG)
See also
Jump to Replace or not? - Replace runs slowly. Replace always creates a copy of the input string, even if no replacement occurs, and making the copy is. Replacing characters in a string: About Basics Of Visual Basic 6. Hey, I am in small prob guys, Need your help. Prob: I am developing a program which is GUI on VB6.
Definition
Returns a new string in which all occurrences of a specified Unicode character or String in the current string are replaced with another specified Unicode character or String.
Overloads
Replace(String, String, Boolean, CultureInfo)Replace(String, String, Boolean, CultureInfo)Replace(String, String, Boolean, CultureInfo)Replace(String, String, Boolean, CultureInfo) | |
Replace(Char, Char)Replace(Char, Char)Replace(Char, Char)Replace(Char, Char) | Returns a new string in which all occurrences of a specified Unicode character in this instance are replaced with another specified Unicode character. |
Replace(String, String)Replace(String, String)Replace(String, String)Replace(String, String) | Returns a new string in which all occurrences of a specified string in the current instance are replaced with another specified string. |
Replace(String, String, StringComparison)Replace(String, String, StringComparison)Replace(String, String, StringComparison)Replace(String, String, StringComparison) |
Replace(String, String, Boolean, CultureInfo)Replace(String, String, Boolean, CultureInfo)Replace(String, String, Boolean, CultureInfo)Replace(String, String, Boolean, CultureInfo)
Parameters
- newValue
- StringStringStringString
- culture
- CultureInfoCultureInfoCultureInfoCultureInfo
Returns
Replace(Char, Char)Replace(Char, Char)Replace(Char, Char)Replace(Char, Char)
Returns a new string in which all occurrences of a specified Unicode character in this instance are replaced with another specified Unicode character.
Parameters
- oldChar
- CharCharCharChar
The Unicode character to be replaced.
- newChar
- CharCharCharChar
The Unicode character to replace all occurrences of
oldChar
.Returns
A string that is equivalent to this instance except that all instances of
oldChar
are replaced with newChar
. If oldChar
is not found in the current instance, the method returns the current instance unchanged.Examples
The following example creates a comma separated value list by substituting commas for the blanks between a series of numbers.
Remarks
This method performs an ordinal (case-sensitive and culture-insensitive) search to find
oldChar
. Note
This method does not modify the value of the current instance. Instead, it returns a new string in which all occurrences of
oldChar
are replaced by newChar
. Because this method returns the modified string, you can chain together successive calls to the Replace method to perform multiple replacements on the original string. Method calls are executed from left to right. The following example provides an illustration.
Concat(Object)Concat(Object)Concat(Object)Concat(Object)
Insert(Int32, String)Insert(Int32, String)Insert(Int32, String)Insert(Int32, String)
Join(String, String[])Join(String, String[])Join(String, String[])Join(String, String[])
Remove(Int32, Int32)Remove(Int32, Int32)Remove(Int32, Int32)Remove(Int32, Int32)
Split(Char[])Split(Char[])Split(Char[])Split(Char[])
Substring(Int32)Substring(Int32)Substring(Int32)Substring(Int32)
Replace(String, String)Replace(String, String)Replace(String, String)Replace(String, String)
Returns a new string in which all occurrences of a specified string in the current instance are replaced with another specified string.
Parameters
- oldValue
- StringStringStringString
The string to be replaced.
- newValue
- StringStringStringString
The string to replace all occurrences of
oldValue
.Returns
A string that is equivalent to the current string except that all instances of
oldValue
are replaced with newValue
. If oldValue
is not found in the current instance, the method returns the current instance unchanged.Exceptions
ArgumentNullExceptionArgumentNullExceptionArgumentNullExceptionArgumentNullException
oldValue
is null
.ArgumentExceptionArgumentExceptionArgumentExceptionArgumentException
oldValue
is the empty string (').Examples
The following example demonstrates how you can use the Replace method to correct a spelling error.
Remarks
If
newValue
is null
, all occurrences of oldValue
are removed. Note
This method does not modify the value of the current instance. Instead, it returns a new string in which all occurrences of
oldValue
are replaced by newValue
. This method performs an ordinal (case-sensitive and culture-insensitive) search to find
oldValue
. Because this method returns the modified string, you can chain together successive calls to the Replace method to perform multiple replacements on the original string. Method calls are executed from left to right. The following example provides an illustration.
Concat(Object)Concat(Object)Concat(Object)Concat(Object)
Insert(Int32, String)Insert(Int32, String)Insert(Int32, String)Insert(Int32, String)
Join(String, String[])Join(String, String[])Join(String, String[])Join(String, String[])
Remove(Int32, Int32)Remove(Int32, Int32)Remove(Int32, Int32)Remove(Int32, Int32)
Split(Char[])Split(Char[])Split(Char[])Split(Char[])
Substring(Int32)Substring(Int32)Substring(Int32)Substring(Int32)
Replace(String, String, StringComparison)Replace(String, String, StringComparison)Replace(String, String, StringComparison)Replace(String, String, StringComparison)
Parameters
- newValue
- StringStringStringString
- comparisonType
- StringComparisonStringComparisonStringComparisonStringComparison
Returns
Applies to
Active2 years, 7 months ago
i have a problem right now. Im using textfile as my database. Here is the format of my Strings inside the textfile.
01/Alarm1/01:00:00
01/Alarm2/02:00:00
01/Alarm3/03:00:00
For example i just want to rename the Alarm2 but it will keep the 01 on the beginning and the time on it. Thanks for help guys
CeciliACeciliA
2 Answers
Please find an example on which you can rely on in order to:
- read a text file
- update its content
- write it back
Hope this will help you.
Jeandey BorisJeandey Boris
- open txt file;
loop begin
- get the string(by rows) - lets consider it is 'someStr'
- you can use NewStr = Replace(someStr,'Alarm','Warning')
- write NewStr to a new file
loop end
close both files
arifarif