Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# string manipulation

Tags:

string

c#

I have string of 9 letters.

string myString = "123987898";

I want to retrieve the first 3 letters "123" then 2 more letters "98" and then 4 more letters "7898".

Which c# string function support this functionality.

like image 230
Novice Developer Avatar asked Mar 11 '10 18:03

Novice Developer


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

Is C language easy?

Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.

What is C in C language?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.

What is C full form?

History: The name C is derived from an earlier programming language called BCPL (Basic Combined Programming Language). BCPL had another language based on it called B: the first letter in BCPL.


1 Answers

You can use Substring:

myString.Substring(0,3)
myString.Substring(3,2)
myString.Substring(5,4)

It's also possible to make it more complicated than necessary by using a combination of regular expressions and LINQ:

string myString = "123987898";
Regex regex = new Regex("(.{3})(.{2})(.{4})");
string[] bits = regex
    .Match(myString)
    .Groups
    .Cast<Group>()
    .Skip(1)
    .Select(match => match.Value)
    .ToArray();
like image 153
Mark Byers Avatar answered Nov 05 '22 18:11

Mark Byers