Page 1 of 1 1
Topic Options
#64019 - 2002-03-22 04:40 PM Removing commas from string
Viggen Offline
Starting to like KiXtart

Registered: 2002-03-22
Posts: 110
Hello!

How do I remove commas from a string?

I have a string that look like this:
1,234,567

I need to get it to look like this:
1234567

I think that I can use SPLIT() to create some sort of array, but I can't get it "back together"

It seems to be quite simple, but I'm sitting here, going:
-"que... [Confused] Me know nothing"

/V.O

Top
#64020 - 2002-03-22 04:57 PM Re: Removing commas from string
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
You could use your old favourites InStr() and SubStr...
code:
$sData="1,234,567"
$i=InStr($sData,",")
While $i
$sData=SubStr($sData,1,$i-1) + SubStr($sData,$i+1)
$i=InStr($sData,",")
Loop

(This code not tested, but you get the idea [Wink] )

Top
#64021 - 2002-03-22 05:37 PM Re: Removing commas from string
Viggen Offline
Starting to like KiXtart

Registered: 2002-03-22
Posts: 110
This almost works...

I started with the line:
1,234,567
after the first loop it looked like this:
1234,567
then:
134,567
then:
14,567
then:
1,567
then:
1567
then:
167
then:
17
then:
1

and after that it starts an endles loop that return 1 everytime.

any clues?

/V.O

Top
#64022 - 2002-03-22 06:54 PM Re: Removing commas from string
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Interesting... works for me!

What version KiX? OS?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#64023 - 2002-03-22 07:06 PM Re: Removing commas from string
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Well... if 3.62, then this should do it.

code:
break on
$sData="1,234,567"
$i=InStr($sData,",")
While $i
$sData=SubStr($sData,1,$i-1) + SubStr($sData,$i+1,Len($sData))
$i=InStr($sData,",")
$sData ?
Loop
Get $_

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#64024 - 2002-03-22 08:05 PM Re: Removing commas from string
Viggen Offline
Starting to like KiXtart

Registered: 2002-03-22
Posts: 110
Hi!
The server is NT4
The klient is Win98SE
Kixver. is 4.02

I will try the other code on monday when I'm back at work.

Top
#64025 - 2002-03-22 08:33 PM Re: Removing commas from string
New Mexico Mark Offline
Hey THIS is FUN
****

Registered: 2002-01-03
Posts: 223
Loc: Columbia, SC
Since you are using 4.02, for about the same cost in code you could just use the Strip() UDF. Being a little more generic, you might be able to reuse it for other things in your script.

http://www.scriptlogic.com/Kixtart/FunctionList.asp?FT=String%20-and-%20Array%20Functions

New Mexico Mark

Top
#64026 - 2002-03-22 11:13 PM Re: Removing commas from string
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
here some thing like this..

code:
$string = "1,234,567"
$newstring = ""

for each $thing in split($string,",")
$newstring = $newstring+$thing
next
? $newstring


Top
#64027 - 2002-03-22 11:34 PM Re: Removing commas from string
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Well Bryce... so far, I think you've got the prize! [Big Grin]
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#64028 - 2002-03-23 02:24 PM Re: Removing commas from string
Viggen Offline
Starting to like KiXtart

Registered: 2002-03-22
Posts: 110
I just had to go downtown to work an test this....

It works!!   [Big Grin] [Big Grin]

thanks guys!

Top
#64029 - 2002-03-23 06:19 PM Re: Removing commas from string
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Just curious... why couldn't you test it at home? I can see nothing that would be dependent on OS or a network or anything like that. I test all sorts of things at home, just not Wintendo issues.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#64030 - 2002-03-23 10:51 PM Re: Removing commas from string
Viggen Offline
Starting to like KiXtart

Registered: 2002-03-22
Posts: 110
He,he...
I had the scripts at work, so instead of rewriting them, I went to my work and tried it there.

Top
#64031 - 2002-03-24 08:09 AM Re: Removing commas from string
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Yeah... dedication Les, something you used to have before you got tired of your job [Razz]

Hey... maybe you could use a few copies of VMWARE VMWARE - Productivity Tool for Technical Professionals to run an "internal" network. Have not tried it, but hey... it may be possible if it supports virtual nic

Maybe I'll try that some time myself and see if it works. Run your own little network of machines all from one machine.

Top
#64032 - 2002-03-24 10:30 AM Re: Removing commas from string
Anonymous
Unregistered


Vmware works better than perfect; that is how I test my client server projects. If I want to copy files from the vmware virt. computer to my host w2k box I prefer ftp.
Top
#64033 - 2002-03-24 03:28 PM Re: Removing commas from string
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
EH DOC,
Don't talk to me about dedication. I'm wired into my home so I can (and do) just about everything from home.
Ive got a dedicated Terminal server and all my Win2k servers have TS enabled as well. NT4 servers have SMS. I RAS in to web-enabled NMS and my WhatsUp emails and pages me day or night. I trend everything as well with MRTG.

I'd put in a dedicated DSL line if it were not for the fact I live too far from town and we have a lousy TelCo. I am considering wireless though.

The only thing I can't (won't) do is test Wintendo 'cuz I won't have one in my house. (did I ever mention that I hate Wintendo?)

{edit}
OK, so maybe I ranted just a little. My apologies. Just noticed ya wuz razzing (it worked). I didn't lose my dedication... just got lazy. [Big Grin]
Who was it that said laziness is the mother of invention?

[ 24 March 2002, 16:14: Message edited by: LLigetfa ]
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
Page 1 of 1 1


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

Who's Online
0 registered and 2009 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.088 seconds in which 0.062 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