mirror of
https://github.com/S7NetPlus/s7netplus.git
synced 2026-02-17 14:28:25 +08:00
S7.Net and S7.Net.Core unification (issue #56): moved files, updated csproj, minor modification for compatibility in SocketClient class.
Signed-off-by: Michele Cattafesta <michele.cattafesta@mesta-automation.com>
This commit is contained in:
34
S7.Net/Types/String.cs
Normal file
34
S7.Net/Types/String.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
namespace S7.Net.Types
|
||||
{
|
||||
public static class String
|
||||
{
|
||||
// publics
|
||||
#region ToByteArray
|
||||
public static byte[] ToByteArray(string value)
|
||||
{
|
||||
string txt = (string)value;
|
||||
char[] ca = txt.ToCharArray();
|
||||
byte[] bytes = new byte[txt.Length];
|
||||
for (int cnt = 0; cnt <= ca.Length - 1; cnt++)
|
||||
bytes[cnt] = (byte)Asc(ca[cnt].ToString());
|
||||
return bytes;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region FromByteArray
|
||||
public static string FromByteArray(byte[] bytes)
|
||||
{
|
||||
return System.Text.Encoding.ASCII.GetString(bytes);
|
||||
}
|
||||
#endregion
|
||||
|
||||
// privates
|
||||
private static int Asc(string s)
|
||||
{
|
||||
byte[] b = System.Text.Encoding.ASCII.GetBytes(s);
|
||||
if (b.Length > 0)
|
||||
return b[0];
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user