Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
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 23:20pm
Comments
Mehdi Gholam at 23-Apr-13 4:22am
   
Show what you want to do in code as your question does not make sense.
Rate this: bad
good
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.
  Permalink  
Comments
@AmitGajjar at 23-Apr-13 4:41am
   
Perfect with different example. 5+
Mohi Uddin Sumon at 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 at 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
good
Please Sign up or sign in to vote.

Solution 2

Hi,
 
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.
  Permalink  
Comments
Mohi Uddin Sumon at 23-Apr-13 4:46am
   
I have posted a question before this. Please answer that
@AmitGajjar at 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
0 Sergey Alexandrovich Kryukov 504
1 Maciej Los 349
2 Kornfeld Eliyahu Peter 325
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,303
1 DamithSL 4,764
2 Maciej Los 4,306
3 Kornfeld Eliyahu Peter 3,914
4 Sergey Alexandrovich Kryukov 3,538


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 23 Apr 2013
Copyright © CodeProject, 1999-2014
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