locate string in string and copy the substring onwards - multithreading

cstring str1="hello world!";
cstring str2="or";
I need to locate str2 in str1 and copy string "orld!" or "ld!"
but in my application, I dont know the content of str1.
could you help to figure out how to do this?

Related

Substring when found character in a string in vba

I have folder path is string same as below:
"D:\aaaa\bbbb\cccc\eeee\ffff\abcd.txt"
Then i would like to get 2 string as below:
Str1 = "bbbb"
Str2 = "ffff"
My idea is that I would be like this. I would first find the position of "" then substring by index. but I don't know how to implement it.
So anyone can you help me this problem in vba.

how to compare the string and store the difference in a variable. c++

str1="D:\\User\\Desktop\\result.jpg";
str2="D:\\User\\Desktop\\";
I want to get the difference between str1 and str2, which is "result.jpg" so that i could use the string "result.jpg" for something else.
Any solution?
I would use string replace and find:
std::string string = std::regex_replace(string1, std::regex("\\" + str2), "");
It is only pseudocode.

how to find string in another string by using vba only

So I have
Dim str1
str1 = "Cat"
Dim str2
str2 = "concatenate"
I wanted to know is there a way I can match str1 with str2 and return positive non-zero number if there is match (case-insensitive) for str1 in str2 ?
For VBA, The instr is the way to go:
InStr(1, str2, str1, vbTextCompare)
The first part is where it starts looking, in this case the first character.
The second is the string in which the search is happening.
The third is the search parameter.
The fourth determines whether it looks at the text of the binary value. So for a case-insensitive we use vbtextcompare.
Use the indexOf method:
str2.indexOf(str1)
Use instr or instrrev:
instr(str2, str1, 1)
See msdn for more info.
This does exactly what you need.

Comparing one string to another string using compareTo method

When comparing string to another string using compareTO() method, here we compare one string to another string right. My doubt is which one is argument string in this two
example : int result = str1.compareTo( str2 );
If you write
str1.compareTo(str2)
then you get back an integer that is
negative if str1 precedes str2,
zero if str1 equals str2, and
positive if str1 is comes after str2.
Here, str1 is the receiver object (since it comes before the dot) and str2 is the argument.

Blackberry Java replace char \n

I have an example string get from XML, contains: Hello\nWorld\n\nClick\nHere.\nThanks.
And then i want to replace the \n char with space char.
Already try using string replace, string substring, string indexOf. But cannot detect the \n char, iam trying using '\r\n' to detect, but didnt work.
String hello = "Hello\nWorld\n\nClick\nHere.\nThanks.";
String afterReplace = hello.replace('\n', ' ');
But still cannot remove/replace the \n with space.
Anyone can help me?
Thanks a lot.
If I understand correctly you have a string which when printed shows the \n characters and does not actually skip a line.
Hello\nWorld\n\nClick\nHere.\nThanks. would be represented in code by:
String s = "Hello\\nWorld\\n\\nClick\\nHere.\\nThanks."
Now s is equal to what you would obtain from your XML.
Try this:
String afterReplace = hello.replace('\\n', ' ');

Resources