Title Case#
Operations / Transform / Title Case
Can Read
Cannot Write
Description#
Converts the first character of every word to upper case and the rest to lower case
Parameters#
| Name | Description |
|---|---|
| Text | The text that is converted |
Code#
using System;
using System.Globalization;
using UnityEngine;
using VisualScript.Icons;
namespace VisualScript.Runtime
{
[Get]
[Title("Title Case")]
[Category("Operations/Transform/Title Case")]
[Description("Converts the first character of every word to upper case and the rest to lower case")]
[Image(typeof(IconString), ColorTheme.Type.Yellow, typeof(BadgeString))]
[Parameter("Text", "The text that is converted")]
[Keywords("Capitalize", "Word", "Proper", "Text")]
[Serializable]
public class TypeStringTitleCase : TypeString
{
[SerializeField] private GetString m_Text = new GetString();
public override string GetPreview(GameObject source) => TitleCase(this.m_Text.GetPreview(source));
public override string Get(Args args) => TitleCase(this.m_Text.Get(args));
private static string TitleCase(string text)
{
if (string.IsNullOrEmpty(text)) return string.Empty;
return CultureInfo.InvariantCulture.TextInfo.ToTitleCase(text.ToLowerInvariant());
}
public override string ToString()
{
return $"Title {this.m_Text}";
}
protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
}
}