Click here to Skip to main content
15,921,716 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all,
I need to split a string if the string length is greater than 45 and store that it into a variable.

Suppose string is "
Two Thousand Four Hundred Ninety Three Dirhams and Twenty Eight Fils 
" -Here I need to split the string at 5th space and store the splitted parts to two variable.
How to do this.Any help will be really appreciated.

What I have tried:

string lab7 = label7.Text.Length.ToString();

if (int.Parse(lab7) >= 45)
          {
                      //here need to store the splitted strings to variables
          }
Posted
Updated 20-Oct-17 19:56pm
Comments
PIEBALDconsult 21-Oct-17 0:17am    
Please do not do a ToString on an integer followed by a Parse or Convert right back to an integer! For Bob's sake!
PIEBALDconsult 21-Oct-17 0:29am    
I don't quite follow what you want, but I do have a way to split a string into sections no longer than some specified length, and it could be used to split your sample into:
Two Thousand Four Hundred Ninety
Three Dirhams and Twenty Eight Fils

You need to read the documentation about string functions, a few of them allow you to get a part of a string.
 
Share this answer
 
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.

So start by looking at either a Regex (Search for "Regular Expressions c#") and get a copy of Expresso[^] - it's free, and it examines and generates Regular expressions, or look at the string handling functions: string.Split, string.IndexOf, and string.Substring methods.

Try it yourself, you may find it is not as difficult as you think!
 
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