https://github.com/skibitsky/string-formatter
👨👩👧 Format strings with HTML-like tags (Unity's Rich Text) in LINQ fashion
https://github.com/skibitsky/string-formatter
csharp rich-text unity upm-package
Last synced: about 1 year ago
JSON representation
👨👩👧 Format strings with HTML-like tags (Unity's Rich Text) in LINQ fashion
- Host: GitHub
- URL: https://github.com/skibitsky/string-formatter
- Owner: skibitsky
- License: mit
- Created: 2021-03-28T12:32:21.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2022-11-14T09:19:11.000Z (over 3 years ago)
- Last Synced: 2025-04-04T19:16:10.233Z (about 1 year ago)
- Topics: csharp, rich-text, unity, upm-package
- Language: C#
- Homepage:
- Size: 19.5 KB
- Stars: 22
- Watchers: 5
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# String Formatter [](https://openupm.com/packages/com.skibitsky.string-formatter/)
> Format strings with HTML-like tags (Unity's Rich Text) in LINQ fashion
## Usage
```csharp
// Without String Formatter
Debug.Log($"Player's name: {name}");
// With String Formatter
Debug.Log($"Player's name: {name.Bold().Italic().Size(16).Red()});
// Reuse
var nameFormat = new FormattedStringBuilder().Bold().Italic().Size(16).Red();
Debug.Log($"Player One name: {nameFormat.Appy(name1)});
Debug.Log($"Player Two name: {nameFormat.Appy(name2)});
// Extend
public static FormattedStringBuilder Dead(this FormattedStringBuilder source)
{
source.Append("Player "); // Add before string. Used for opening tags
source.PushToEnd(" is dead!"); // Add after string. Used for closing tags
return source.Bold().Italic(); // Also make string bold and italic
}
public static FormattedStringBuilder Dead(this string source) => new FormattedStringBuilder(source).Dead();
```
## Installation
### Install via OpenUPM
The package is available on the [openupm registry](https://openupm.com). It's recommended to install it via [openupm-cli](https://github.com/openupm/openupm-cli).
```
openupm add com.skibitsky.string-formatter
```
### Install via Git URL
Open *Packages/manifest.json* with your favorite text editor. Add the following line to the dependencies block.
{
"dependencies": {
"com.skibitsky.string-formatter": "https://github.com/skibitsky/string-formatter.git"
}
}
Notice: Unity Package Manager records the current commit to a lock entry of the *manifest.json*. To update to the latest version, change the hash value manually or remove the lock entry to resolve the package.
"lock": {
"com.skibitsky.string-formatter": {
"revision": "master",
"hash": "..."
}
}