#include <iostream.h>
#include <string.h>
#include <string.hpp>
void display(String & s)
{
cout << "length = " << s.length() << endl;
int u = strcspn( s.c_str(), "0123456789"); // Error!
cout << "u = " << u << endl;
}
// つづく
int main(int argc, char *argv[])
{
const int COUNT = 4096;
String id("bcd10023");
int id_length = id.length();
switch(argc) {
case 2:
if(! strcmp(argv[1], "-e") ) { // Errorになるオプション
String s = id(id_length, COUNT);
display(s);
} else {
display(id);
}
break;
default:
display(id);
break;
}
return 0;
}
C:\work>cspan
length = 8
u = 3
C:\work>cspan -e
length = 0
The instruction at 0x00401412 referenced memory at 0x00000000.
The memory could not be read.
C:\work>cspan -s
length = 8
u = 3
部分文字列です
sub-sequenceは、posからはじまって、len個つづきます
The sub-sequence begins at offset pos within the String object and continues for len characters.
String::operator ()()
Synopsis: #include <string.hpp>
public:
String String::operator ()( size_t pos, size_t len ) const;
Semantics: This form of the operator () public member function extracts a sub-sequence of characters from
the String object. A new String object is created that contains the sub-sequence of characters.
The sub-sequence begins at offset pos within the String object and continues for len characters. The
first character of a String object is at position zero.
If pos is greater than or equal to the length of the String object, the result is empty.
If len is such that pos + len exceeds the length of the object, the result is the sub-sequence of characters
from the String object starting at offset pos and running to the end of the String object.
Results: The operator () public member function returns a String object.
See Also: String::operator [], operator char, operator char const *
String Class 873
cpplib.pdf
// substri.cpp
#include <iostream.h>
#include <string.hpp>
int main(int argc, char *argv[])
{
const int COUNT = 4096;
String id("bcd10023");
int id_length = id.length();
String s = id(id_length, COUNT);
cout << "s: length = " << s.length() << endl;
cout << s << endl;
int count = 3;
int begin = 3;
String g = id(begin, count);
cout << "g: length = " << g.length() << endl;
cout << g << endl;
return 0;
}
/*
C:\work>substri
s: length = 0
g: length = 3
100
*/