String.Replace メソッド (Char, Char)
アセンブリ: mscorlib (mscorlib.dll 内)

Dim instance As String Dim oldChar As Char Dim newChar As Char Dim returnValue As String returnValue = instance.Replace(oldChar, newChar)
戻り値
このインスタンスと等価であり、oldChar のすべてのインスタンスが newChar に置換されている String。


連続した番号の間にある空白をコンマに置き換えることで、コンマ区切りの値リストを作成するコード例を次に示します。
Imports System _ Class stringReplace1 Public Shared Sub Main() Dim str As [String] = "1 2 3 4 5 6 7 8 9" Console.WriteLine("Original string: ""{0}""", str) Console.WriteLine("CSV string: ""{0}""", str.Replace(" "c, ","c)) End Sub End Class ' ' This example produces the following output: ' Original string: "1 2 3 4 5 6 7 8 9" ' CSV string: "1,2,3,4,5,6,7,8,9" '
using System; class stringReplace1 { public static void Main() { String str = "1 2 3 4 5 6 7 8 9"; Console.WriteLine("Original string: \"{0}\"", str); Console.WriteLine("CSV string: \"{0}\"", str.Replace(' ', ',')); } } // // This example produces the following output: // Original string: "1 2 3 4 5 6 7 8 9" // CSV string: "1,2,3,4,5,6,7,8,9" //
using namespace System; int main() { String^ str = "1 2 3 4 5 6 7 8 9"; Console::WriteLine( "Original string: \"{0}\"", str ); Console::WriteLine( "CSV string: \"{0}\"", str->Replace( ' ', ',' ) ); } // // This example produces the following output: // Original string: "1 2 3 4 5 6 7 8 9" // CSV string: "1,2,3,4,5,6,7,8,9" //
import System.*; class StringReplace1 { public static void main(String[] args) { String str = "1 2 3 4 5 6 7 8 9"; Console.WriteLine("Original string: \"{0}\"", str); Console.WriteLine("CSV string: \"{0}\"", str.Replace(' ', ',')); } //main } //StringReplace1 // // This example produces the following output: // Original string: "1 2 3 4 5 6 7 8 9" // CSV string: "1,2,3,4,5,6,7,8,9" //

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


String.Replace メソッド (String, String)
アセンブリ: mscorlib (mscorlib.dll 内)

Dim instance As String Dim oldValue As String Dim newValue As String Dim returnValue As String returnValue = instance.Replace(oldValue, newValue)
戻り値
このインスタンスと等価であり、oldValue のすべてのインスタンスが newValue に置換されている String。



Replace メソッドを使用して、スペルの間違いを訂正する方法については、次のコード例を参照してください。
Imports System Public Class ReplaceTest Public Shared Sub Main() Dim errString As String = "This docment uses 3 other docments to docment the docmentation" Console.WriteLine("The original string is:{0}'{1}'{0}", Environment.NewLine, errString) ' Correct the spelling of "document". Dim correctString As String = errString.Replace("docment", "document") Console.WriteLine("After correcting the string, the result is:{0}'{1}'", Environment.NewLine, correctString) End Sub End Class ' ' This code example produces the following output: ' ' The original string is: ' 'This docment uses 3 other docments to docment the docmentation' ' ' After correcting the string, the result is: ' 'This document uses 3 other documents to document the documentation' '
using System; public class ReplaceTest { public static void Main() { string errString = "This docment uses 3 other docments to docment the docmentation"; Console.WriteLine("The original string is:{0}'{1}'{0}", Environment.NewLine, errString); // Correct the spelling of "document". string correctString = errString.Replace("docment", "document"); Console.WriteLine("After correcting the string, the result is:{0}'{1}'", Environment.NewLine, correctString); } } // // This code example produces the following output: // // The original string is: // 'This docment uses 3 other docments to docment the docmentation' // // After correcting the string, the result is: // 'This document uses 3 other documents to document the documentation' //
using namespace System; int main() { String^ errString = "This docment uses 3 other docments to docment the docmentation"; Console::WriteLine( "The original string is:\n'{0}'\n", errString ); // Correct the spelling of S"document". String^ correctString = errString->Replace( "docment", "document" ); Console::WriteLine( "After correcting the string, the result is:\n'{0}'", correctString ); } // // This code example produces the following output: // // The original string is: // 'This docment uses 3 other docments to docment the docmentation' // // After correcting the string, the result is: // 'This document uses 3 other documents to document the documentation' //
import System.*; public class ReplaceTest { public static void main(String[] args) { String errString = "This docment uses 3 other docments to docment " + "the docmentation"; Console.WriteLine("The original string is:{0}'{1}'{0}", Environment.get_NewLine(), errString); // Correct the spelling of "document". String correctString = errString.Replace("docment", "document"); Console.WriteLine("After correcting the string, the result is:{0}'{1}'", Environment.get_NewLine(), correctString); } } // // This code example produces the following output: // // The original string is: // 'This docment uses 3 other docments to docment the docmentation' // // After correcting the string, the result is: // 'This document uses 3 other documents to document the documentation' //
import System; public class ReplaceTest { public static function Main() : void { var errString : String = "This docment uses 3 other docments to docment the docmentation"; Console.WriteLine("The original string is:{0}'{1}'{0}", Environment.NewLine, errString); // Correct the spelling of "document". var correctString : String = errString.Replace("docment", "document"); Console.WriteLine("After correcting the string, the result is:{0}'{1}'", Environment.NewLine, correctString); } } ReplaceTest.Main();

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


String.Replace メソッド

名前 | 説明 |
---|---|
String.Replace (Char, Char) | このインスタンスに出現する指定 Unicode 文字をすべて、別に指定した Unicode 文字に置換します。 .NET Compact Framework によってサポートされています。 |
String.Replace (String, String) | このインスタンスに出現する指定 String 文字をすべて、別に指定した String 文字に置換します。 .NET Compact Framework によってサポートされています。 |

- String.Replaceのページへのリンク