Read text from flash

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.