-3

i want to search a text written just next to a string or text in ini and copy it or directly read from TINI into TEdit.

i.e.

[Section]
Indent=AA1:BB2ac:CC35sda:DDWord`

i want to show the text written next to CC,which is 35sda, in TEdit.

I Tried copy function but not the pos and posex() function. Thank You.

bear
  • 43
  • 6
  • 1
    Welcome to SO! Please, take [**The Tour**](http://stackoverflow.com/tour) for a brief intro on Stack Overflow, and then read [**Asking**](http://stackoverflow.com/help/asking) to learn what you can ask about and how to present your question. – Tom Brunberg Jan 07 '18 at 12:49
  • If you want to do something, why not do it. That's not a question. – David Heffernan Jan 07 '18 at 13:03
  • i didn't find the way to do it so i asked here sir. – bear Jan 07 '18 at 13:07
  • 3
    What have you done sofar, why did that not work as expected? Mind you, we are not here to write your code. Read the links I provided in my previous comment. – Tom Brunberg Jan 07 '18 at 13:10
  • You might want to read the Delphi documentation on the string processing functions. You should be able to get ideas there. – lurker Jan 07 '18 at 14:02
  • 1
    It doesn't look like you made any effort. Are we to write your entire program? You can't read an ini file. You can't read substrings? What are able to do? If you can't do these basic things, asking here isn't going to be productive. – David Heffernan Jan 07 '18 at 15:24
  • @bear, there is several example on web (for Windows) about how make what you want, only adapt some example to `firemonkey`. Then if after this happens some trouble, you can ask here on S.O showing your code. –  Jan 07 '18 at 15:29

1 Answers1

3

This is simply a matter of basic string parsing, such as with Pos(), PosEx(), and Copy(), eg:

Ini := TMemIniFile.Create('file.ini');
try
  S := Ini.ReadString('Section', 'Indent', '');
  StartIdx := Pos(':CC', S) + 3;
  EndIdx := PosEx(':', S, StartIdx);
  Edit1.Text := Copy(S, StartIdx, EndIdx - StartIdx);
finally
  Ini.Free;
end;

Or, using TStringHelper:

Ini := TMemIniFile.Create('file.ini');
try
  S := Ini.ReadString('Section', 'Indent', '');
  StartIdx := S.IndexOf(':CC') + 3;
  EndIdx := S.IndexOf(':', StartIdx);
  Edit1.Text := S.Substring(StartIdx, EndIdx - StartIdx);
finally
  Ini.Free;
end;

Or, you could use a TStringList to help you parse, eg:

Ini := TMemIniFile.Create('file.ini');
try
  SL := TStringList.Create;
  try
    SL.Delimiter := ':';
    SL.StrictDelimiter := True;
    SL.DelimitedText := Ini.ReadString('Section', 'Indent', '');
    Edit1.Text := Copy(SL[2], 3, MaxInt);
    // or:
    // Edit1.Text := SL[2].Substring(2);
  finally
    SL.Free;
  end;
finally
  Ini.Free;
end;
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • 1
    This type of question not deserves a final solution as answer. None effort was made by OP. –  Jan 08 '18 at 00:04
  • @JeffersonFarias I chose to point a newbie in a direction, and give examples of it. – Remy Lebeau Jan 08 '18 at 02:25
  • I'm also a newbie, but i makes effort to deserves this type of solution, that not is case of OP. But ok if this was your choose ;-) –  Jan 08 '18 at 02:53
  • @RemyLebeau Thank you very much for the answer. – bear Jan 08 '18 at 06:04
  • 3
    @JeffersonFarias yes, you are a newbie, but you are the kind that doesn't listen and learn, and that makes things difficult. This was a simple question with a simple answer. That wasn't the case with you – Remy Lebeau Jan 08 '18 at 06:07
  • @Everyone sorry for the trouble i create. i'll make sure next time to show what i tried. But don't know how this is of topic. – bear Jan 08 '18 at 06:22
  • 1
    @bear Read the link in the close notice. It should help explain things. I'll add that because you didn't provide the code that you had tried (**nb: copy-paste; don't try re-type**) we had no idea what you were struggling with. _You might have been having been failing to read the file for all we know._ Clearly from your update you had been struggling with a few particular functions. Even then providing the code you have that's not working would have allowed us to explain to you ***why*** it's not working. – Disillusioned Jan 08 '18 at 07:17
  • It's off topic for the reason stated in the close notice. Did you read the close notice carefully, following the links. If not this suggests a tendency to shy away from important detail and learning. – David Heffernan Jan 08 '18 at 08:22