0

I'm trying to get a text that is placed between two word.

Project Name - this is the text I want to get, Contact Name -

how can I get exactly the Project Name without the first text and the last?

I Tried this code but it takes the Contact Name content too:

int Place1 = SecondText.IndexOf("Project Name");
int Place2 = SecondText.IndexOf("Contact Name");
Name = SecondText.Substring(Place1, Place2);
NameTB.Text = Name;

I have created a Cleaner function which deletes the words Project Name and Contact Name But the contact name stays in my string.

Thanks for helping.

user2992413
  • 77
  • 1
  • 8

2 Answers2

0

Put it like that:

  String SecondText = "Project Name - this is the text I want to get, Contact Name -";

  // Pay attention to + + "Project Name".Length; and - Place1
  int Place1 = SecondText.IndexOf("Project Name") + "Project Name".Length;
  int Place2 = SecondText.IndexOf("Contact Name") - Place1;
  Name = SecondText.Substring(Place1, Place2);
Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215
0

try this code

string SecondText = "Project Name - this is the text I want to get, Contact Name";
string result = SecondText.Replace("Project Name - ","");
int Place2 = result.IndexOf(", Contact Name");
string Name = result.Substring(0, Place2);

i hope this works for you

user3840692
  • 273
  • 2
  • 13