Solved

c#, array issue

Posted on 2013-10-29
9
173 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
Comment Utility
Hi

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

Raj
0
 

Author Comment

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

Expert Comment

by:Rajkumar Gs
Comment Utility
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
Comment Utility
Hi - any update on this ?

Raj
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:solution1368
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Your codes are working. I just need more helps later ... Thanks
0
 
LVL 23

Expert Comment

by:Rajkumar Gs
Comment Utility
you are welcome
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 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

14 Experts available now in Live!

Get 1:1 Help Now