Page 1 of 1 1
Topic Options
#42783 - 2003-07-14 02:32 PM Replacing text
Josh R Offline
Fresh Scripter
****

Registered: 2003-05-07
Posts: 49
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 "\"?

Top
#42784 - 2003-07-14 02:38 PM Re: Replacing text
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Try:
$line = join(split($line,","),"\")

More info (for fun): http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=14;t=000882
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#42785 - 2003-07-14 02:47 PM Re: Replacing text
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
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.
_________________________
There are two types of vessels, submarines and targets.

Top
#42786 - 2003-07-14 02:49 PM Re: Replacing text
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
$KeyName = EnumKey("HKEY_CURRENT_USER\Printers\Connections\", $Index)
$KeyName = Replace($KeyName,',','\')

code:
Function Replace($Str,$From,$To)
$Replace = Join(Split($Str,$From),$To)
ENDFUNCTION



[ 14. July 2003, 14:51: Message edited by: Radimus ]
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#42787 - 2003-07-14 02:59 PM Re: Replacing text
Josh R Offline
Fresh Scripter
****

Registered: 2003-05-07
Posts: 49
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?
Top
#42788 - 2003-07-14 03:03 PM Re: Replacing text
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
you can put the value in quotes so it will be kept in the field even though it contains commas.
_________________________
!

download KiXnet

Top
#42789 - 2003-07-14 03:04 PM Re: Replacing text
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
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 ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#42790 - 2003-07-14 03:06 PM Re: Replacing text
Josh R Offline
Fresh Scripter
****

Registered: 2003-05-07
Posts: 49
I think I already do have the text in quotes?
Top
#42791 - 2003-07-14 03:07 PM Re: Replacing text
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
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:
How can I replace these commas with a "\"?
_________________________
There are two types of vessels, submarines and targets.

Top
#42792 - 2003-07-14 03:09 PM Re: Replacing text
Josh R Offline
Fresh Scripter
****

Registered: 2003-05-07
Posts: 49
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.
Top
#42793 - 2003-07-14 03:10 PM Re: Replacing text
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
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

_________________________
There are two types of vessels, submarines and targets.

Top
#42794 - 2003-07-14 03:11 PM Re: Replacing text
Josh R Offline
Fresh Scripter
****

Registered: 2003-05-07
Posts: 49
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.
Top
#42795 - 2003-07-14 03:16 PM Re: Replacing text
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
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.
_________________________
There are two types of vessels, submarines and targets.

Top
#42796 - 2003-07-14 03:17 PM Re: Replacing text
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
yep.
like many of us quessed.
you need to write also the quotes around the data if it contains commas.

just like told.
_________________________
!

download KiXnet

Top
#42797 - 2003-07-14 03:22 PM Re: Replacing text
Josh R Offline
Fresh Scripter
****

Registered: 2003-05-07
Posts: 49
Ok there are 5 - 6 totally differnt solutions. Which ONE actually works? I have tried all of them and nothing works right.
Top
#42798 - 2003-07-14 03:29 PM Re: Replacing text
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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.
_________________________
!

download KiXnet

Top
#42799 - 2003-07-14 03:31 PM Re: Replacing text
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
"Code on a silver platter"TM
code:
$Index = 0
:Loop2
$KeyName = EnumKey("HKEY_CURRENT_USER\Printers\Connections\", $Index)
$KeyName = join(split($KeyName ,","),"\")
If @ERROR = 0
? "$KeyName"
$Index = $Index + 1
GoTo Loop2
EndIf

Oh, and please refrain form using GOTOs in your code, see for example the ArayEnumKEY() UDF.

[ 14. July 2003, 15:32: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#42800 - 2003-07-14 04:38 PM Re: Replacing text
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
See also Deleting commas..... .
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 466 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.07 seconds in which 0.023 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org