Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ Replace() [2/4]

string System.String.Replace ( string oldValue,
string? newValue )
inline

Definition at line 2436 of file String.cs.

2437 {
2438 if ((object)oldValue == null)
2439 {
2440 throw new ArgumentNullException("oldValue");
2441 }
2442 if (oldValue.Length == 0)
2443 {
2444 throw new ArgumentException(SR.Argument_StringZeroLength, "oldValue");
2445 }
2446 if ((object)newValue == null)
2447 {
2448 newValue = Empty;
2449 }
2450 Span<int> initialSpan = stackalloc int[128];
2452 if (oldValue.Length == 1)
2453 {
2454 if (newValue.Length == 1)
2455 {
2456 return Replace(oldValue[0], newValue[0]);
2457 }
2458 char value = oldValue[0];
2459 int num = 0;
2460 while (true)
2461 {
2462 int num2 = SpanHelpers.IndexOf(ref Unsafe.Add(ref _firstChar, num), value, Length - num);
2463 if (num2 == -1)
2464 {
2465 break;
2466 }
2467 valueListBuilder.Append(num + num2);
2468 num += num2 + 1;
2469 }
2470 }
2471 else
2472 {
2473 int num3 = 0;
2474 while (true)
2475 {
2476 int num4 = SpanHelpers.IndexOf(ref Unsafe.Add(ref _firstChar, num3), Length - num3, ref oldValue._firstChar, oldValue.Length);
2477 if (num4 == -1)
2478 {
2479 break;
2480 }
2481 valueListBuilder.Append(num3 + num4);
2482 num3 += num4 + oldValue.Length;
2483 }
2484 }
2485 if (valueListBuilder.Length == 0)
2486 {
2487 return this;
2488 }
2489 string result = ReplaceHelper(oldValue.Length, newValue, valueListBuilder.AsSpan());
2490 valueListBuilder.Dispose();
2491 return result;
2492 }
string ReplaceHelper(int oldValueLength, string newValue, ReadOnlySpan< int > indices)
Definition String.cs:2494
static readonly string Empty
Definition String.cs:29
char _firstChar
Definition String.cs:35
string Replace(string oldValue, string? newValue, bool ignoreCase, CultureInfo? culture)
Definition String.cs:2324

References System.String._firstChar, System.SR.Argument_StringZeroLength, System.String.Empty, System.SpanHelpers.IndexOf(), System.String.Length, System.String.Replace(), System.String.ReplaceHelper(), and System.value.