Because the company wants to provide data to other companies, there are characters to replace in the data. There are two replacement methods
Code1:
Public Static Void Main ()
{
StringInput1= "";
Stringbuilder SB1 = New Stringbuilder ();
For ( Int I = 0 ; I < 50000 ; I ++ )
{
Sb1.append ( " Wo \ r " );
}
Input1 = Sb1.tostring ();
WL ( " SB test date is complate .. " );
Stopwatch SW1 = New Stopwatch ();
// Char
Sw1.start ();
Stringbuilder sb = New Stringbuilder ();
If (Input1 ! = String. Empty)
{
For ( Int I = 0 ; I < Input1.length; I ++ )
{
Switch (Input1 [I])
{
Case ( Char ) 13 :
SB. append ( " " );
Break ;
Case ( Char ) 10 :
SB. append ( " " );
Break ;
Default :
SB. append (input1 [I]);
Break ;
}
}
Input1 = SB. tostring ();
}
Sw1.stop ();
WL (sw1.elapsedmilliseconds + " Millisecond " );
RL ();
}
Code 2:
Public Static Void Main ()
{
String Input1 = "" ;
Stringbuilder SB1 = New Stringbuilder ();
For ( Int I = 0 ; I < 50000 ; I ++ )
{
Sb1.append ( " Wo \ r " );
}
Input1 = Sb1.tostring ();
WL ( " Replace test date is complate .. " );
Stopwatch SW1 = New Stopwatch ();
// Char
Sw1.start ();
Input1 = Input1.replace ( " \ R " , " " );
Input1 = Input1.replace ( " \ N " , " " );
Sw1.stop ();
WL (sw1.elapsedmilliseconds + " Millisecond " );
RL ();
}
Figure1: 6 s
Figure2: 3 S