Recently I have been thinking about a game conversation system, which requires reading specific content from text files. So I designed it like this :( Code Segment) mystring2 is the static global variable npctalkid used to save the specified position index of the searched string
Mytxt. Text = event.tar get. Data; // display the text content in the text box for exchanging with mytxt2
Mystring = mytxt. Text; // The string read by mytxt. Text is assigned to mystring.
Npctalkid = mystring. Search ("npcman"); // obtain the npcman location, which is the first n location.
Npctalkid + = 6; // skip the npcman string itself. The string itself will not appear when it is displayed later.
For (var I: Int = 0, j = 1; I <mytxt. length; I ++, J ++)
{
If (mystring. substring (npctalkid + I, npctalkid + J )! = '#') // Select a sentence.
{
Mystring2 + = mystring. substring (npctalkid + I, npctalkid + J); // use static variables for data storage
}
Else
Break; // when the searched character is '#', stop searching and exit the loop.
}
Mytxt2.text = mystring2;
Using the code above, you can find the sentence after the specified string npcman in the text file (I use '#' as the end character of a sentence ).
the above is my experience in the "actual project". Before doing this, I did not see how much information was shared online. So I decided to express what I thought of to help those who needed help like me and provide them with a solution to this problem. If you are interested, you can also study and discuss them together.