none
string manipulation to get middle string on vb.net

    Question

  • I have these string, and i need to pull out only the words after "on" and before "has"

    So far here's my code:                lstAuthors.Items.Add(objItem("Outcome").ToString().Remove(0, 21))

    Approval Workflow on industrial has successfully completed. All participants have completed their tasks.

    Approval Workflow on pharmaceutical has successfully completed. All participants have completed their tasks.

    Output:

    Industrial

    Pharmaceutical


    cal_bonjovi

    Thursday, May 17, 2012 7:41 AM

Answers

  • Hi,

     Please find the following code

    lstAuthors.Items.Add(objItem("Outcome").ToString().Substring(objItem("Outcome").ToString().IndexOf("on", 0) + 2, objItem("Outcome").ToString().IndexOf("has", 0) - 3).Trim());

    Hope it will help you..


    Sai Kumar K http://www.santoshtechnologies.com http://saimaterial.wordpress.com

    • Marked as answer by cal_bonjovi Thursday, May 17, 2012 12:14 PM
    Thursday, May 17, 2012 8:05 AM

All replies

  • Hi,

     Please find the following code

    lstAuthors.Items.Add(objItem("Outcome").ToString().Substring(objItem("Outcome").ToString().IndexOf("on", 0) + 2, objItem("Outcome").ToString().IndexOf("has", 0) - 3).Trim());

    Hope it will help you..


    Sai Kumar K http://www.santoshtechnologies.com http://saimaterial.wordpress.com

    • Marked as answer by cal_bonjovi Thursday, May 17, 2012 12:14 PM
    Thursday, May 17, 2012 8:05 AM
  • Hi, 

    you can have, 

    	private string TextBetween(string text, string startwith, string endwith)
    		{
    			var startIndex = text.IndexOf(startwith) + startwith.Length;
    			var endIndex = text.IndexOf(endwith);
    			if (startIndex < endIndex)
    			{
    				return text.Substring(startIndex, (endIndex - startIndex));
    			}
    			return text; // or  null
    		}


    and have a call like, 

    var d = TextBetween("Approval Workflow on industrial has successfully completed. All participants have completed their tasks", "on", "has");

    you can change same code to VB

    I hope this helps you...


    If this post answers your question, please click "Mark As Answer". If this post is helpful please click "Mark as Helpful".

    Thursday, May 17, 2012 8:21 AM