Without knowing the actual size of the string literal you will not do the task.
If you know the size then you can use constructor
basic_string(const charT* s, size_type n, const Allocator& a = Allocator());
or the corresponding method assign
Here the second parameter specifies the number of characters of s that will be copied in the string.
If the length is know then you can write simply
std::string clean( raw, n );
or
std::string clean;
clean.assign( raw, n );
EDIT: As you changed your original message then I will append my post. You can split the literal the following way
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
int main()
{
const char * s = "text1\0\0text2\0\0\0text3\0more text";
size_t n = 30;
std::istringstream is( std::string( s, 30 ) );
std::vector<std::string> v;
std::string word;
while ( std::getline( is, word, '\0' ) ) if ( !word.empty() ) v.push_back( word );
for ( const std::string &s : v ) std::cout << s << std::endl;
}
The output is
text1
text2
text3
more text
If you have four different strings you can write
#include <iostream>
#include <sstream>
#include <string>
int main()
{
const char * s = "text1\0\0text2\0\0\0text3\0more text";
size_t n = 30;
std::istringstream is( std::string( s, 30 ) );
std::string word1, word2, word3, word4;
while ( std::getline( is, word1, '\0' ) && word1.empty() );
while ( std::getline( is, word2, '\0' ) && word2.empty() );
while ( std::getline( is, word3, '\0' ) && word3.empty() );
while ( std::getline( is, word4, '\0' ) && word4.empty() );
for ( const std::string &s : { word1, word2, word3, word4 } ) std::cout << s << std::endl;
}