|
|
|||||||
I am exporting mapped printers by using the following code: $Index = 0 :Loop2 $KeyName = EnumKey("HKEY_CURRENT_USER\Printers\Connections\", $Index) If @ERROR = 0 ?"$KeyName" $Index = $Index + 1 GoTo Loop2 EndIf When I export it there are commas in the text which makes it space out in the file. How can I replace these commas with a "\"? |
||||||||
|
|
|||||||
Try: $line = join(split($line,","),"\") More info (for fun): http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=14;t=000882 |
||||||||
|
|
|||||||
And take a look at the UDF Library, you will find some helpful UDF in there with regards to enumerating registry keys/values and printer mapping/inventory. |
||||||||
|
|
|||||||
$KeyName = EnumKey("HKEY_CURRENT_USER\Printers\Connections\", $Index) $KeyName = Replace($KeyName,',','\') code:Function Replace($Str,$From,$To) [ 14. July 2003, 14:51: Message edited by: Radimus ] |
||||||||
|
|
|||||||
I am not sure if I explained myself that well. When the data shows up in the csv document (I am using excel to view it) it is showing up in the third column because of the double commas. Does that make more sense? |
||||||||
|
|
|||||||
you can put the value in quotes so it will be kept in the field even though it contains commas. |
||||||||
|
|
|||||||
You did not say you were writing a comma delimited text file. You will either need to write a TAB delimited text or wrap the text that contains commas in quotes. [ 14. July 2003, 15:05: Message edited by: Howard Bullock ] |
||||||||
|
|
|||||||
I think I already do have the text in quotes? |
||||||||
|
|
|||||||
You have still been provided the solution to your problem, all the code fragments posted above will replace commas in a string with the back-slash character. Please explain in detail why this does not solve your originally posted problem quote: |
||||||||
|
|
|||||||
When the registry key is read the CSV file is reading the commas and moving the data to a new column. That is my issue. |
||||||||
|
|
|||||||
If you try to include a comma as part of a text string inside a comma-delimited file, then thet complete text string must be enclosed in quotes code:text,text,"text with , comma",text |
||||||||
|
|
|||||||
When the registry key is read the CSV file is reading the commas and moving the data to a new column. That is my issue. |
||||||||
|
|
|||||||
Again, the code fragments above will replace the commas with back-slashes, as requested by you. Thus, having unwanted commas in your CSV-file is no longer an issue. |
||||||||
|
|
|||||||
yep. like many of us quessed. you need to write also the quotes around the data if it contains commas. just like told. |
||||||||
|
|
|||||||
Ok there are 5 - 6 totally differnt solutions. Which ONE actually works? I have tried all of them and nothing works right. |
||||||||
|
|
|||||||
there is 2 solutions provided to you. the first ones are what you asked, to replace comma's with back slashes. then, we decided to go further and told you that you could just insert the quotes in the file around the data so the comma's don't matter anymore. now, if you have tried these and 4 other ones... dude, I must ask you to show your code. |
||||||||
|
|
|||||||
"Code on a silver platter"TM code:Oh, and please refrain form using GOTOs in your code, see for example the ArayEnumKEY() UDF.$Index = 0 [ 14. July 2003, 15:32: Message edited by: sealeopard ] |
||||||||
|
|
|||||||
See also Deleting commas..... . |