Line 6 is read, I need that after the word AUTHENTIC_DOMAIN = the address AUTHENTIC_DOMAIN = 127.0.0.1 is read

Here is the line itself in the File.ReadLines code (@ "service.ini"). ElementAt (6);

Closed due to the fact that the essence of the question is not clear to the participants of 0xdb , yolosora , EvgeniyZ , Andrew , Kromster 16 Nov '18 at 11:51 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

1 answer 1

I will answer, not to this question, but to another. Which, in fact, the author is interested more than this - "how to read / process data in INI files?"

using System.Runtime.InteropServices; using System.Text; namespace BotAgent.DataExporter { public class Ini { public string Path; [DllImport("kernel32")] private static extern long WritePrivateProfileString(string section, string key, string val, string filePath); [DllImport("kernel32")] private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath); public Ini(string iniPath) { Path = iniPath; } /// <summary> /// Works with "Default" section /// </summary> public void Write(string key, string value) { WritePrivateProfileString("Default", key, value, Path); } /// <summary> /// Write Data to the INI File /// </summary> /// <PARAM name="section"></PARAM> /// section name /// <PARAM name="key"></PARAM> /// key Name /// <PARAM name="value"></PARAM> /// value Name public void Write(string section, string key, string value) { WritePrivateProfileString(section, key, value, Path); } /// <summary> /// Works with "Default" section /// </summary> public string Read(string key) { StringBuilder temp = new StringBuilder(255); int i = GetPrivateProfileString("Default", key, "", temp, 255, Path); return temp.ToString(); } /// <summary> /// Read Data value From the Ini File /// </summary> /// <PARAM name="section"></PARAM> /// <PARAM name="key"></PARAM> /// <PARAM name="Path"></PARAM> /// <returns></returns> public string Read(string section, string key) { StringBuilder temp = new StringBuilder(255); int i = GetPrivateProfileString(section, key, "", temp, 255, Path); return temp.ToString(); } } } 

The code is taken from here: https://github.com/ukushu/DataExporter/


Well, if you really answer this:

  • if this is guaranteed the beginning of the line:

var a = someString.SubString(17, someString.Length - 17);

  • If the value is in the middle of a string, then regular expressions should be used here. Google on Regex C #
  • This is not the case, the fact is that I don’t know how to count the data in the 6th line after the Word AUTHENTIC_DOMAIN = But I know how easy it is to count the 6th line - Andryukha Raise
  • I answered this question - the second part, after the underscore. But it's better to look at the part you really need - it goes first. Believe me, the first part of the answer you need;) - Andrew
  • Do not quite understand how to apply it - Andryukha Raise
  • The line goes like this - textBoxServerIP.Text = File.ReadLines (@ "service.ini"). ElementAt (6); - Andryukha Raise
  • one
    Seriously, come on cleanliness, do not "can not remember" but "I do not know and never knew." Come up to the teacher and let him explain my answer to you ... Honestly, I wrote a 100 times more detailed answer than was required. If you do not understand how to apply it, then this is already a defect or your efforts in studies or the efforts of your teacher (which I doubt). Better than with the application of this class you can not write. And let the teacher explain to you why. - Andrew