Skip to content

Commit 80fd77d

Browse files
committed
readme
1 parent 202661e commit 80fd77d

File tree

1 file changed

+47
-2
lines changed

1 file changed

+47
-2
lines changed

README.md

+47-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,55 @@ ZString
22
===
33
[![CircleCI](https://circleci.com/gh/Cysharp/ZString.svg?style=svg)](https://circleci.com/gh/Cysharp/ZString)
44

5-
WIP
6-
75
**Z**ero Allocation **String**Builder for .NET Core and Unity.
86

7+
Currently Preview Release, -0.1.0.
8+
9+
Getting Started(Unity, with TextMeshPro)
10+
---
11+
Check the [releases](https://github.com/Cysharp/ZString/releases) page, download `ZString.Unity.unitypackage`.
12+
13+
```csharp
14+
TextMeshProUGUI text; // TMP_Text
15+
int count = 0;
16+
17+
void Update()
18+
{
19+
label.SetTextFormat("Damage: {0}", count++);
20+
}
21+
```
22+
23+
SetTextFormat is extension method of `TMP_Text`, there parameter is generics so can avoid boxing, and ZString writes to buffer directly without any ToString allocation. Finally inner buffer copy to `TextMeshPro` buffer so avoid all string allocations.
24+
25+
```
26+
public static void SetTextFormat<T0>(this TMP_Text text, string format, T0 arg0)
27+
public static void SetTextFormat<T0, T1>(this TMP_Text text, string format, T0 arg0, T1 arg1)
28+
// ...
29+
public static void SetTextFormat<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>(this TMP_Text text, string format, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15)
30+
```
31+
32+
Raw API is start from `ZString.CreateStringBuilder();`.
33+
34+
```csharp
35+
using(var sb = ZString.CreateStringBuilder())
36+
{
37+
sb.Append("foo");
38+
sb.AppendLine(42);
39+
sb.AppendFormat("{0} {1}", "bar", 123.456);
40+
sb.AppendMany(1, "foo", 100, "bar");
41+
42+
Debug.Log(sb.ToString());
43+
}
44+
45+
// If you want to use only format, use `ZString.Format` instead of `String.Format`.
46+
var str = ZString.Format("foo {0} bar {1}", 42, 123.456);
47+
```
48+
49+
Getting Started(.NET Core)
50+
---
51+
52+
> PM> Install-Package [ZString](https://www.nuget.org/packages/ZString)
53+
954
```csharp
1055
using var sb = ZString.CreateStringBuilder();
1156

0 commit comments

Comments
 (0)