Click here to Skip to main content
13,191,400 members (79,453 online)
Rate this:
Please Sign up or sign in to vote.
See more:
How can I assign string value in string array. Is split method required to do this. If so, Why do we have to use Split() Method.
Posted 22-Apr-13 22:20pm
Mehdi Gholam 23-Apr-13 4:22am
Show what you want to do in code as your question does not make sense.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You can't "assign a string value in a string array" - you can assign a strign vlaue to an element of a string array, but you can only assign arrays to arrays and vice versa.
So you can do this:
string s = "Hello there";
string[] arr = new string[5];
arr[2] = s;
But you can't do this:
string s = "Hello there";
string[] arr = s;
because the types are not compatible.

You can use Split to break a string into an array of substrings:
string s = "Hello there";
string[] arr = s.Split(' ');

which will give you an array of two strings, containing "hello" and "there".
This is very useful when separating user input strings for example:
string s = "Smith;John;2 Letsbe Avenue, Luton";
string[] arr = s.Split(';');
would break the input into the various address parts.
@AmitGajjar 23-Apr-13 4:41am
Perfect with different example. 5+
Mohi Uddin Sumon 23-Apr-13 4:47am
Thank you. Please give the answer that I posted here before this question. I will be very regretful if I get it.
OriginalGriff 23-Apr-13 4:52am
Sorry? I do not understand what you are saying. It's probably a language problem, or a lack of coffee on my part, but please try again. Perhaps if you write it in your native language and use Google Translate to convert it to English?
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


You need split function because you need to specify on what basis you want to convert string into array. example : you have comma separated mobile number and if you want to convert it into array then you need to split with the comma.

Let us know what is your exact query with code.

best luck.
Mohi Uddin Sumon 23-Apr-13 4:46am
I have posted a question before this. Please answer that
@AmitGajjar 23-Apr-13 4:52am
Please post some code so we can give you exact answer.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.171017.1 | Last Updated 23 Apr 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100