I have a null-terminated string, with a pointer to the first element in eax . I found the position to which you want to trim the string from the end. A pointer to this position is stored in ebx . It is necessary for the string to continue from eax to ebx , and not from eax to the null terminator. How do I write a \0 character in ebx ?

I also tried this:

 mov edi, ebx mov esi, eax add esi, dword ptr [esp + 16] ; в esp + 16 у меня длина строки movsb 

But still the length of the string has not changed.

  • Maybe just mov byte ptr [ebx], 0 ? - Mike
  • @Mike wouldn't it be number 0? - kostya
  • Yes, there will be a number 0, one byte equal to zero is your null character. How do you imagine a null character? - Mike
  • @Mike is understandable, but for some reason it still prints the entire line to the old zero - kostya
  • one
    @NicolasChabanovsky But I don’t even know what to do. The text of the question itself has nothing to do with the real essence of the problem. And the author himself will probably figure out the essence, after the experiments, which were prompted by my comments. Then it will be necessary to completely change the text of the question and he will be able to answer it himself :) Either close it by “no longer playing” - Mike

1 answer 1

You (judging by the comments) are confusing the string with the zero terminating byte in the C language, and the string string in C ++. In C ++, you formally do not have the right to do anything with the string returned by .data() - theoretically it could be a copy of the string at all, and not itself. But in practice, this usually passes (although I will not talk about all compilers!) ... except that the string length in string not determined by the null character. So, it may well be a string consisting of a dozen null characters.

Here is a piece of code for VC ++:

 int main(int argc, const char * argv[]) { string s(" "); const char * data = s.data(); _asm { mov ebx, data mov byte ptr [ebx + 1], 0 } cout << s.length() << endl; cout << strlen(s.c_str()) << endl; } 

Displays

 3 1