|
|
||||||||
Hi, I would like to clear speech marks out of varable, how can this be done (Sure it is quite simple) Example: I have a csv file with a line like this "firstname","surname" I import it in to a String and it looks like this : "firstname" and I would like to take away the " to give me this firstname Darren |
|||||||||
|
|
||||||||
hmm ... sure thing : get rid of the Quotations in the csv file ! Possible ? |
|||||||||
|
|
||||||||
Sure, the simple solution is just to use InStr() and SubStr() if you can be sure of what is in the fields. Be aware if you are trying to parse MicroSoft format CSV files with unknown data that it can get pretty messy. You will need to cater for strings which have commas in them, and worse, strings which have speech marks in them. Try creating a spread sheet in Excel which has cells containing the (,) character and some containing the (") character. Now save it as a CSV file. It's not impossible to decode it, but you will go cross-eyed looking at all the speech marks. |
|||||||||
|
|
||||||||
heres the hard but idiotic way of doing it (assuming that you have seperated it by commas) script: break on csv file : code:it was really hard to create this csv by other editors than Notepad"John","Doe" (Richard is damn RIGHT !!!) {edit#2} Oh yeah , please feel free to play Golf with this snippet above {/edit} [ 31. January 2003, 13:41: Message edited by: jpols ] |
|||||||||
|
|
||||||||
How does it get on with this: code:Horrible, huh?The following field contains a comma,"Doe, John" This is an example generated from Excel. Each row contains only two fields, the second fiels which when unpacked should read: quote: [ 31. January 2003, 14:21: Message edited by: Richard H. ] |
|||||||||
|
|
||||||||
errrggg .... *Jochen flees with fear ! |
|||||||||
|
|
||||||||
Hey , who needs to work with csv anyway ? Why don't you have that as Excel and simply read the contents via the beautiful and easy to understand 'Office COM Interface' |
|||||||||
|
|
||||||||
Or use an ODBC connection to the Excel file? |
|||||||||
|
|
||||||||
Here is a UDF which should work in all situations. It returns an array containing each field from the line:
Here is an example of how to use it:
[ 31. January 2003, 15:23: Message edited by: Richard H. ] |
|||||||||
|
|
||||||||
errg ... not speaking of the UDF Richard (which is of course great as always) but the colors Nice thing : On my LCD I didn't see the backColor(Light Yellow) but on my CRT {edit: Now also visible on LCD ... damn contrats eh ? {/edit} Think that table stuff is an Option to add for PostPrep 1.3 ... JOOOOOEEEL !!! [ 31. January 2003, 16:07: Message edited by: jpols ] |
|||||||||
|
|
||||||||
Hi, Not so sure how I should use this UDF? Using this text in a csv : "whittington","darren" Hope to get somthing like this: Darren Whittington,dwhittington,group Darren code: |
|||||||||
|
|
||||||||
reading your script shows that the source file has already: "first last,username,group" form... you probably would call it then as: join(fnCSV2Array ($sourceline),",") basically what I say is that I have no idea where you would use it as you have already code that does it all the way around... [ 03. February 2003, 11:47: Message edited by: Lonkero ] |
|||||||||
|
|
||||||||
Hi Lonkero, My source file is "surname","firstname"? Running as sugested with join(fnCSV2Array ($sourceline),",") just before the ;Split File comment I get this as output: "firstname" "surname",""surname",GROUP Darren |
|||||||||
|
|
||||||||
Darren, The UDF splits the line automatically into an array, you don't need to do it again. If you have a csv file that contains code:thenApple,Pear,"A bunch of bananas" code:Will give you an array that you can manipulate directly containing:$sourcearray=fnCSV2Array($sourceline)
[ 03. February 2003, 12:27: Message edited by: Richard H. ] |
|||||||||
|
|
||||||||
Thanks.. All fine now Darren |