Solved

c#, array issue

Posted on 2013-10-29
9
179 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

785 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