Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i want to find a perticular string from a label and delete that string from label. label contains a long string but i want to select a substring(in c#)
... please help me out
Posted
Comments
Dean Oliver 20-Mar-12 2:24am    
Is this wpf or winforms?
Sergey Alexandrovich Kryukov 20-Mar-12 2:26am    
A valid question, but does it matter in this very case?
--SA

using the Substring method
http://www.dotnetperls.com/substring[^]

C#
string input = "OneTwoThree";

    // Get first three characters
    string sub = input.Substring(0, 3);
    Console.WriteLine("Substring: {0}", sub); //result One
 
Share this answer
 

You can use a Regex for that purpose.


See also the MSDN topic about Regular Expression Language.

 
Share this answer
 
How about reading some MSDN before asking questions like that?
Please see:
http://msdn.microsoft.com/en-us/library/system.string.aspx[^],
http://msdn.microsoft.com/en-us/library/hxthx5h6.aspx[^],
http://msdn.microsoft.com/en-us/library/aka44szs.aspx[^].

And of course, all Label types (there are more than one) have string properties to assign a value to, such as "Text" or "Context"…

I guess what you really need it this:
Microsoft QQ209354.


—SA
 
Share this answer
 
If it is a contineous string within the main string use String.IndexOf(subString) method to find the starting point of the sub string in the main string.

If you wish to remove it altogether, use String.Replace(subString, "").

HTH!
 
Share this answer
 
Hi,

Does this[^] help you?

Regards
Sebastian
 
Share this answer
 
Comments
[no name] 20-Mar-12 3:06am    
Dean Oliver posted the same link. Please check
Sebastian T Xavier 20-Mar-12 8:09am    
yes.. but not intentional

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