user19294: I have the code, it's purpose is to receive the string from a comport like:
Set@1234567890123456@1234567890123456@1234567890123456@1234567890123456
and translate it into four byte arrays byte user1[16], user2[16], pass1[16], pass2[16]. Here's the code:
String inString = ""; // COM port incoming data buffer

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println("Start");
}

void loop() {
  // put your main code here, to run repeatedly:
  // Receive data from com port
  while (Serial.available() > 0) {
    int inChar = Serial.read();


    if (inChar != '\n') {
      inString += (char)inChar;
    } else {
      // New line
      String Action = inString.substring(0, 3);
      if (Action == "Set") {
        SetCard(inString);
      } else if (Action == "Get") {
        Serial.println("1");
      } else {
        Serial.println(Action);
      }
      inString = "";
    }
  }
}

void SetCard(String Data) {
  Serial.println(Data);
  // Data Set@user1@user2@pass1@pass2
  // Set@1234567890123456@1234567890123456@1234567890123456@1234567890123456
  byte user1[16], user2[16], pass1[16], pass2[16];

  String user1str = inString.substring(4, 20);
  String user2str = inString.substring(21, 37);
  String pass1str = inString.substring(38, 54);
  String pass2str = inString.substring(55, 71);

  Serial.println("Strings");
  Serial.println(user1str);
  Serial.println(user2str);
  Serial.println(pass1str);
  Serial.println(pass2str);

  Serial.println("Arrays");
  user1str.getBytes(user1, 16);
  user2str.getBytes(user2, 16);
  pass1str.getBytes(pass1, 16);
  pass2str.getBytes(pass2, 16);


  writeByteArray(user1, 16);
  writeByteArray(user2, 16);
  writeByteArray(pass1, 16);
  writeByteArray(pass2, 16);
}

void writeByteArray(byte array[], int arrlength)
{
  for (int j = 0 ; j < arrlength ; j++) //print the block contents
  {
    Serial.write (array[j]);//Serial.write() transmits the ASCII numbers as human readable characters to serial monitor
  }
  Serial.println("");
}

When I run this code and send my string through a com port I expect the output:
Start
Set@1234567890123456@1234567890123456@1234567890123456@1234567890123456
Strings
1234567890123456
1234567890123456
1234567890123456
1234567890123456
Arrays
1234567890123456
1234567890123456
1234567890123456
1234567890123456

And yet, I receive
Start
Set@1234567890123456@1234567890123456@1234567890123456@1234567890123456
Strings
1234567890123456
1234567890123456
1234567890123456
1234567890123456
Arrays
123456789012345
123456789012345
123456789012345
123456789012345

Why? And how do I receive desired output?
getBytes docs

user80581: Using String.getBytes(buffer, len) to get bytes.
"len" is the length to copy, but usually need to add 1 for the end of string '\0'.
For example:
String s = "123";
int count = s.length();  // lenth() is 3
s.getBytes(buffer, count);   // copied "12\0" => HEX(31 32 00)
s.getBytes(buffer, count + 1);   // copied "123\0" => HEX(31 32 33 00)

The official document not mentioned those above, and it's not reasonable for the modern function design.
Misunderstanding in that and waste our life so much.

user13432: 
Why? And how do I receive desired output? getBytes docs

The String member function getBytes() will null-terminate the string. You must add space for that. 
  byte user1[17], user2[17], pass1[17], pass2[17];
  ...
  user1str.getBytes(user1, sizeof(user1));
  ...
  Serial.print((char*) user1);

That should do the trick.

19294: <p>I have the code, it's purpose is to receive the string from a comport like:
<code>Set@1234567890123456@1234567890123456@1234567890123456@1234567890123456</code>
and translate it into four byte arrays <code>byte user1[16], user2[16], pass1[16], pass2[16]</code>. Here's the code:</p>

<pre><code>String inString = ""; // COM port incoming data buffer

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println("Start");
}

void loop() {
  // put your main code here, to run repeatedly:
  // Receive data from com port
  while (Serial.available() &gt; 0) {
    int inChar = Serial.read();


    if (inChar != '\n') {
      inString += (char)inChar;
    } else {
      // New line
      String Action = inString.substring(0, 3);
      if (Action == "Set") {
        SetCard(inString);
      } else if (Action == "Get") {
        Serial.println("1");
      } else {
        Serial.println(Action);
      }
      inString = "";
    }
  }
}

void SetCard(String Data) {
  Serial.println(Data);
  // Data Set@user1@user2@pass1@pass2
  // Set@1234567890123456@1234567890123456@1234567890123456@1234567890123456
  byte user1[16], user2[16], pass1[16], pass2[16];

  String user1str = inString.substring(4, 20);
  String user2str = inString.substring(21, 37);
  String pass1str = inString.substring(38, 54);
  String pass2str = inString.substring(55, 71);

  Serial.println("Strings");
  Serial.println(user1str);
  Serial.println(user2str);
  Serial.println(pass1str);
  Serial.println(pass2str);

  Serial.println("Arrays");
  user1str.getBytes(user1, 16);
  user2str.getBytes(user2, 16);
  pass1str.getBytes(pass1, 16);
  pass2str.getBytes(pass2, 16);


  writeByteArray(user1, 16);
  writeByteArray(user2, 16);
  writeByteArray(pass1, 16);
  writeByteArray(pass2, 16);
}

void writeByteArray(byte array[], int arrlength)
{
  for (int j = 0 ; j &lt; arrlength ; j++) //print the block contents
  {
    Serial.write (array[j]);//Serial.write() transmits the ASCII numbers as human readable characters to serial monitor
  }
  Serial.println("");
}
</code></pre>

<p>When I run this code and send my string through a com port I expect the output:</p>

<pre><code>Start
Set@1234567890123456@1234567890123456@1234567890123456@1234567890123456
Strings
1234567890123456
1234567890123456
1234567890123456
1234567890123456
Arrays
1234567890123456
1234567890123456
1234567890123456
1234567890123456
</code></pre>

<p>And yet, I receive</p>

<pre><code>Start
Set@1234567890123456@1234567890123456@1234567890123456@1234567890123456
Strings
1234567890123456
1234567890123456
1234567890123456
1234567890123456
Arrays
123456789012345
123456789012345
123456789012345
123456789012345
</code></pre>

<p>Why? And how do I receive desired output?
<a href="https://www.arduino.cc/en/Reference/StringGetBytes" rel="nofollow">getBytes docs</a></p>
 80581: <p>Using String.getBytes(buffer, len) to get bytes.</p>
<p>&quot;len&quot; is the length to copy, but usually need to add 1 for the end of string '\0'.</p>
<p>For example:</p>
<pre><code>String s = &quot;123&quot;;
int count = s.length();  // lenth() is 3
s.getBytes(buffer, count);   // copied &quot;12\0&quot; =&gt; HEX(31 32 00)
s.getBytes(buffer, count + 1);   // copied &quot;123\0&quot; =&gt; HEX(31 32 33 00)
</code></pre>
<p>The official document not mentioned those above, and it's not reasonable for the modern function design.</p>
<p>Misunderstanding in that and waste our life so much.</p>
 13432: <blockquote>
  <p>Why? And how do I receive desired output? getBytes docs</p>
</blockquote>

<p>The String member function <a href="https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/WString.cpp#L547" rel="nofollow">getBytes</a>() will null-terminate the string. You must add space for that. </p>

<pre><code>  byte user1[17], user2[17], pass1[17], pass2[17];
  ...
  user1str.getBytes(user1, sizeof(user1));
  ...
  Serial.print((char*) user1);
</code></pre>

<p>That should do the trick.</p>
