?
Solved

c#, array issue

Posted on 2013-10-29
9
Medium Priority
?
189 Views
Last Modified: 2013-11-09
I have the following url like

default.aspx?location=["john","smiths","'Los Angeles'","'CA'"],["john","chan","'Fremont'","'CA'"],

and the location parameter may be more or less meaning that it may have more
["xxx","xxx","'xxx'","'xx'"]

In this case of array. How to codes in c#/asp.net to get the value of each one? like the value john, smiths.

Thanks,
0
Comment
Question by:solution1368
  • 5
  • 4
9 Comments
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 39610806
Hi

Use Split function to split the string , pls refer
http://www.dotnetperls.com/split

Raj
0
 

Author Comment

by:solution1368
ID: 39613168
I need working codes to my example. Not just a refer url.  thanks
0
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 39615998
Hi

Posting below the code that I have tested in a console application.

 static void Main(string[] args)
        {

            string inputString = "[john,smiths,'Los Angeles',CA]";
            inputString = inputString.Replace("[", "").Replace("]","").Replace("'","").Replace("\"","");;

            string[] result;
            char[] commaSeparator = new char[] { ',' };

            result = inputString.Split(commaSeparator, StringSplitOptions.None);
            foreach (string str in result)
            {
                Console.WriteLine(str);
            }

            Console.ReadKey();

        } 

Open in new window


Screenshot of Console app with code and output
Regards
Raj
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 39620767
Hi - any update on this ?

Raj
0
 

Author Comment

by:solution1368
ID: 39622423
location=["john","smiths","'Los Angeles'","'CA'"],["john","chan","'Fremont'","'CA'"],

use above data sample. I don't think your codes are working.
0
 
LVL 23

Accepted Solution

by:
Rajkumar Gs earned 2000 total points
ID: 39626623
For the data, location=["john","smiths","'Los Angeles'","'CA'"],["john","chan","'Fremont'","'CA'"],
is the output expecting as below ?
john
smiths
Los Angeles
CA
john
chan
Fremont
CA

If not pls post your expected output

Raj
0
 

Author Comment

by:solution1368
ID: 39628727
working. but I think I should explain more because something still do not work.
for each [ ] that listing name and address. I just hope to happen like array

so it will be like below

<div>
Name
City, State
</div>
<div>
Name
City, State
</div>
0
 

Author Closing Comment

by:solution1368
ID: 39634281
Your codes are working. I just need more helps later ... Thanks
0
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 39635605
you are welcome
0

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question