How would you write a string that has "are" in it:
I beleive this would be a wrong way ?
String GetString = "Hello how "are" you"
somestring = "this is a \"string with \" quotes";
#include <iostream>
#include <string>
int main()
{
std::string text("This string has \"embedded quotes\" in it.");
std::cout << text << "\n";
}
/* my output
This string has "embedded quotes" in it.
*/
Ok, If I now want to check this string if the string contains: "string with" how is the way to do the opposite check for "" within a string ?
String Test = "this is a \"string with\" quotes";
if (Test.Substring(11,13) == ??? ) //"string with"
{}
somestring = "this is a \"string with \" quotes";
well if you want to check for a " in a string then you can write.
if (somestring[n] == ' " ') // i put a space between the single quotes and the double quote so you could see it. in your program just put '"'.
{
//...
Thanks but this does not seem to compile:
'==' : no conversion from 'int' to 'System.String'
'==' : 'System.String' differs in levels of indirection from 'int'
String test = "this is a \"string with\" quotes";
if( test == '"' ){}
what string are you using? std::string or something else?
Sorry, perheps I forgot to tell, I use the:
System.String as my compileerror shows. I am not sure if that would be different.
Thank you.
yes it is. in order to do the comparison you need to tell the code what character to check. like:
for (int i = 0; i < somestring.length; i++
{
if (somestring[i] == '"')
{
//...
}
}
Thank you again, your code works but if I go back to what I am trying to do. To check for a string within a string.
I have tried to put it like this but this does not seem to be correct. Perheps I am missing something out. Thanks.
String test = "this is a \"string with\" quotes";
for (int i = 0; i < test.Length; i++)
{
if (test.Substring(i,14) == '"string with"')
{
MessageBox.Show("Found");
break;
}
}
the size you want for the substring should be 13 not 14. that should help
'"string with"'
is invalid, '' are used for chars, "" are for strings.
"\"string with\""
is that string
Sorry again but what I meen is that this code doesn´t compile. I beleive something must be wrong somewhere in the code ?
The compilerrors is as follows:
too many characters in contant
== no conversion from int to System.String
String test = "this is a \"string with\" quotes";
for (int i = 0; i < test.Length; i++)
{
if (test.Substring(i,13) == '"string with"')
{
MessageBox.Show("Found");
break;
}
}
the size you want for the substring should be 13 not 14. that should help
Thanks that did work:
"\"string with\""
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.