Click here to Skip to main content
15,884,537 members
Please Sign up or sign in to vote.
1.80/5 (4 votes)
See more:
string places very important role in c#
i just want to know 5 methods of string in c#
the easiest one
thanks in advance
: )
Posted
Updated 1-Oct-12 20:29pm
v2

Replace
Substring
EndsWith
StartsWith
Trim

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.
Try it yourself, you may find it is not as difficult as you think!
 
Share this answer
 
Comments
shaikh-adil 2-Oct-12 2:36am    
thats not my homework
:laugh:
but i just want to know the easiest example of string. Just got clicked in mind.
And if i want to use this all in a same example? I just want to use all the five in a simple example? Can i do that?
OriginalGriff 2-Oct-12 2:50am    
Probably - but if it isn't your homework why would you want to?
Normally, we have a task, and look for the methods that make it easiest and quickest to accomplish...
shaikh-adil 2-Oct-12 3:15am    
hey bro. i just want to know. so i asked. all time their should not be a homework
:laugh:
gaining knowledge and nothing else. i found more and tried also
string s1 = "aquib";
string str3 = s1.ToUpper();
Console.WriteLine(str3);
string str2 = str3.ToLower();
Console.WriteLine(str2);
object clone1 = s1.Clone();
Console.WriteLine(clone1.ToString());
string str5 = s1.Replace('a','Y');
Console.WriteLine(str5);
Console.ReadKey();
}
i told ya i am not a coder i am a learner.
and by the way some time some one will also asked this on google and google will redirect here. so this will help them too.
shaikh-adil 2-Oct-12 3:19am    
bro about my regex question i found this one
^(?:[a-zA-Z0-9](?:\.|_|-)?)+[a-zA-Z0-9]$
which is much better but it takes
5421318421 means it takes only numbers also
how to avoid that. can you help me out
Strange question´, but here are the five methods that I think are the easiest or most important ones:
C#
string test = "Hello World";
string[] parts = test.Split(' ');   //splits the string into pieces
bool bIsEmpty = String.IsNullOrWhiteSpace(test);   //checks if the string is empty
int nWhiteSpace = test.IndexOf(' ');   //finds index of first whitespace in string
test = test.Replace(" ", ""); //removes any white space in string
test = test.ToUpper();  //transforms the string to uppercase
 
Share this answer
 
Comments
shaikh-adil 2-Oct-12 2:43am    
thanks jf
It does not work like this here.

Here is what is expected of enquirers:
1. TRY first what you want to do! You may find that it's not that hard.
2. Formulate what was done by you that looks like an issue/not working.

Try them and tell if you face issues.
Members will be more than happy to help like this.



For now, you could have done MSDN and seen: String Methods[^]
- Concat
- Compare
- EndsWith
- Format
- StartsWith
- Subtring
- ToUpper
- ToLower
 
Share this answer
 

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