1
0
mirror of https://github.com/ncblakely/GiantsTools synced 2024-11-04 22:35:37 +01:00
GiantsTools/Giants.BinTools/Extensions.cs
2020-09-05 22:22:23 -07:00

39 lines
962 B
C#

namespace Giants.BinTools
{
using System.IO;
using System.Text;
public static class Extensions
{
/// <summary>
/// Reads a null-terminated C-string from the binary reader.
/// </summary>
public static string ReadCString(this BinaryReader reader)
{
var stringBuilder = new StringBuilder();
while (true)
{
char c = reader.ReadChar();
if (c == '\0')
{
break;
}
stringBuilder.Append(c);
}
return stringBuilder.ToString();
}
/// <summary>
/// Writes a null-terminated C-string to the binary writer.
/// </summary>
public static void WriteCString(this BinaryWriter writer, string value)
{
writer.Write(Encoding.UTF8.GetBytes(value));
writer.Write('\0');
}
}
}