質問

I have a problem where I need to get specific strings out of a text file. This file is a settings file to something so most of the time what I need is contained in one line. I need to copy these unknow strings into textBoxes, but I know the text right before the strings themselves (something like name = cannon where cannon is the string I need) How can I copy from the "=" to the end of the line? (I copied it out into a richTextBox)

役に立ちましたか?

解決

Try this:

string settings = string.Empty;
IEnumerable<string> lines = File.ReadLines(myPath); //reads all lines of text file
foreach (string s in lines) //iterate thru all lines
{
    if s.Contains("=")
    {
        settings = s.substring(s.IndexOf("=")); //get substring from "=" to end of line
        break; //break out of the loop
    }
}

This is basically an expansion of slobodan's answer. Your question is how to copy from "=" to the end of the line, which this does. Your comment on his answer is contradictory, however, as you mention there that it's on multiple lines instead. Let me know what you need and I'll try to change my answer.

他のヒント

Something like text.substring(text.IndexOf("="))

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top