Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
This is my code :

public static string getTitle(string htmltext, string startWord, string endWord)
        {
            int start, end;
            if (htmltext.Contains(startWord) && htmltext.Contains(endWord))
            {
                start = htmltext.IndexOf(startWord, 0) + startWord.Length;
                end = htmltext.IndexOf(endWord, start);
                return htmltext.Substring(start, end - start);
               
                
            }
            else
            {
                return "";
            }
        }


What I have tried:

I want to capitalize the substring from the above code before I display on my label here

string input = textBox1.Text;
label2.Text =  getTitle(input, "https://www.", ".com");
Posted
Updated 10-Oct-21 7:53am
v3
Comments
PIEBALDconsult 10-Oct-21 23:04pm    
You mean like System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase ?
candijen 11-Oct-21 12:11pm    
yes thank you

1 solution

Do you mean the String.ToUpper Method (System) | Microsoft Docs[^]?

If not, you are going to have to be a lot more precise about exactly what you do want ...
 
Share this answer
 
Comments
candijen 10-Oct-21 14:11pm    
I did not want to create another method because I don't know how to code them both and fit it to finally display the substring. I was wondering if there was another way to do it in a single line or something. if not i would appreciate it if you could help me piece the two methods together to display it.
OriginalGriff 10-Oct-21 14:16pm    
Nope, you are going to have to explain exactly what you are trying to do in much better detail than that ... because what you have doesn't return a title at all, it returns a domain (or fails miserably if it isn't a .com domain)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900