Remove#
Operations / Transform / Remove
Can Read
Cannot Write
Description#
Removes every occurrence of a text from another one
Parameters#
| Name | Description |
|---|---|
| Text | The text where the occurrences are searched |
| Remove | The text that is removed from every position it is found |
| Ignore Case | Whether upper and lower case characters are considered the same |
Code#
using System;
using UnityEngine;
using VisualScript.Icons;
namespace VisualScript.Runtime
{
[Get]
[Title("Remove")]
[Category("Operations/Transform/Remove")]
[Description("Removes every occurrence of a text from another one")]
[Image(typeof(IconString), ColorTheme.Type.Yellow, typeof(BadgeCross))]
[Parameter("Text", "The text where the occurrences are searched")]
[Parameter("Remove", "The text that is removed from every position it is found")]
[Parameter("Ignore Case", "Whether upper and lower case characters are considered the same")]
[Keywords("Delete", "Strip", "Erase", "Clean", "Text")]
[Serializable]
public class TypeStringRemove : TypeString
{
[SerializeField] private GetString m_Text = new GetString();
[SerializeField] private GetString m_Remove = new GetString();
[SerializeField] private GetBool m_IgnoreCase = new GetBool(false);
public override string GetPreview(GameObject source) => Remove(
this.m_Text.GetPreview(source),
this.m_Remove.GetPreview(source),
this.m_IgnoreCase.GetPreview(source)
);
public override string Get(Args args) => Remove(
this.m_Text.Get(args),
this.m_Remove.Get(args),
this.m_IgnoreCase.Get(args)
);
private static string Remove(string text, string remove, bool ignoreCase)
{
if (string.IsNullOrEmpty(text) || string.IsNullOrEmpty(remove)) return text ?? string.Empty;
StringComparison comparison = ignoreCase
? StringComparison.OrdinalIgnoreCase
: StringComparison.Ordinal;
return text.Replace(remove, string.Empty, comparison);
}
public override string ToString()
{
return $"Remove {this.m_Remove} from {this.m_Text}";
}
protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
}
}