1
0
mirror of https://github.com/ncblakely/GiantsTools synced 2024-12-05 02:53:08 +01:00
GiantsTools/Giants.BinTools/Extensions.cs

39 lines
962 B
C#
Raw Normal View History

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');
}
}
}