Solved

c#, array issue

Posted on 2013-10-29
9
177 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
 
LVL 23

Expert Comment

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

Raj
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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 500 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

920 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now