473,378 Members | 1,380 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

delimited string test

hey all,
let's say you have a delimited string value of

String value = val1,val2,val3;

and you do something like the following

String s = value.split(',')[3];

well this is outside the range of index, so how can i say if this does occur
just make it an empty string and proceed?

thanks,
rodchar
Mar 26 '08 #1
3 1291
rodchar wrote:
hey all,
let's say you have a delimited string value of

String value = val1,val2,val3;

and you do something like the following

String s = value.split(',')[3];

well this is outside the range of index, so how can i say if this does occur
just make it an empty string and proceed?
Test for it.

string[] values = value.split(',');
string s = values.Length 3 ? values[3] : "";

--
J.
Mar 26 '08 #2
On Mar 26, 4:31*pm, rodchar <rodc...@discussions.microsoft.comwrote:
hey all,
let's say you have a delimited string value of

String value = val1,val2,val3;

and you do something like the following

String s = value.split(',')[3];

well this is outside the range of index, so how can i say if this does occur
just make it an empty string and proceed?

thanks,
rodchar
What about by checking?
string[] parts = myStr.split( new char[]{','});
string d = ( index < parts.Length ) parts[index]: "";
if (
Mar 26 '08 #3
thanks everyone for the help,
rod.

"rodchar" wrote:
hey all,
let's say you have a delimited string value of

String value = val1,val2,val3;

and you do something like the following

String s = value.split(',')[3];

well this is outside the range of index, so how can i say if this does occur
just make it an empty string and proceed?

thanks,
rodchar
Mar 26 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ben | last post by:
Hi all - I am having a bit of trouble and thought maybe someone in this group could shed some light. Here's the skinny... I am creating an automated process to import a bunch of text files...
4
by: Hilary Cotter | last post by:
Thanks for all the help you gave me yesterday. here is another question. I have a comma delimited file called redirect.txt which looks like this test, /test.htm test 123,/test123.htm
9
by: Wayne | last post by:
I have the following string: "smith", "Joe", "West Palm Beach, Fl." I need to split this string based on the commas, but as you see the city state contains a comma. String.split will spilt the...
25
by: electrixnow | last post by:
in MS VC++ Express I need to know how to get from one comma delimited text string to many strings. from this: main_string = "onE,Two,Three , fouR,five, six " to these: string1 =...
15
by: Fariba | last post by:
Hello , I am trying to call a mthod with the following signature: AddRole(string Group_Nam, string Description, int permissionmask); Accroding to msdn ,you can mask the permissions using...
5
by: tom.hepworth | last post by:
Hi I have a problem which I hope someone can help me with because I really don't even know where to start with it. I am using Access 2003. I have a delimited text file which contains about...
7
by: shantanu | last post by:
Hi all i am trying to save a excel file as a tab delimited text file. can i do it some how? i using the code _sheet1.SaveAs(@"C:\PRP \PRPTemp.txt",Excel.XlFileFormat.xlTextWindows...
5
by: RyanL | last post by:
I'm a newbie! I have a non-delimited data file that I'd like to convert to delimited. Example... Line in non-delimited file: 0139725635999992000010100534+42050-102800FM-15+1198KAIA Should...
8
by: =?Utf-8?B?TTFpUw==?= | last post by:
I’m trying to parse out Amazon S3 server logs which are space delimited. However date fields are in the following form: When I try to use the following code to split the record on the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.