Page 1 of 1 1
Topic Options
#124404 - 2004-08-04 02:08 PM Remove first and last Character
AzzerShaw Offline
Seasoned Scripter
****

Registered: 2003-02-20
Posts: 510
Loc: Cheltenham, England
Hi Guys

Can some point me in the right direction to achive the above?

I have a text file that contains computer names. Unfortunetley the names are enclosed in quotes and is messing me script right up. Im trying to use Len and Substr and instr to no avail. Is there anything that i can do?

(I cant put it into an excel file or anything as this is only a sniippet of a massive script)

Any ideas would be welcome

Aaron
_________________________
If at first you don't succeed, try again. Then quit. There's no use being a damn fool about it. - W.C Fields

Top
#124405 - 2004-08-04 02:17 PM Re: Remove first and last Character
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
This should not be too difficult.. Some String manipulation..

Code:

CLS
BREAK ON
; PURPOSE - remove first and last char from a string
$TestStr='AzzyTest'
;Starting with
?$TestStr
;Remove First Char
$EndStr=RIGHT($TestStr,LEN($TestStr)-1)
;Check the Result
?$EndStr
;Remove the Last Char
$StartStr=LEFT($EndStr,LEN($EndStr)-1)
;Check the Result
?$StartStr

Sleep 2



HTH,

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#124406 - 2004-08-04 02:25 PM Re: Remove first and last Character
AzzerShaw Offline
Seasoned Scripter
****

Registered: 2003-02-20
Posts: 510
Loc: Cheltenham, England
IGNORE ME!!!

I'm being thick... worked it out...


Code:
 



Break on

Open (1,"C:\temp\pclist.txt")
Do
$ComLine = ReadLine(1)
$Compname = SubStr($comLine,1,8)
$compname = Trim($compname)


$Fish = Len("$compname")

$Bob = SubStr($compname,2,$Fish)

$bb=Left($bob,Len($bob)-1)

?$bb

Sleep 2

Until $Compname=""





Edited by AzzerShaw (2004-08-04 02:37 PM)
_________________________
If at first you don't succeed, try again. Then quit. There's no use being a damn fool about it. - W.C Fields

Top
#124407 - 2004-08-04 02:32 PM Re: Remove first and last Character
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
;remove first char:
$firstCharRemoved=substr($string,2)
;or:
$firstCharRemoved=right($string,-1)

;remove last char:
$lastCharRemoved=substr($string,1,len($string-1))
;or:
$lastCharRemoved=left($string,-1)

remove first and last char:
$firstAndLastCharRemoved=substr($string,2,len($string-2))
;or:
$firstAndLastCharRemoved=left(right($string,-1),-1)
_________________________
!

download KiXnet

Top
#124408 - 2004-08-04 02:44 PM Re: Remove first and last Character
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Or even (in this case only):
Code:
$s='"This is a quoted string"'
$s=Split($s,Left($s,1))[1]

$s ?


Top
#124409 - 2004-08-04 02:45 PM Re: Remove first and last Character
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
left(right($string,-1),-1)


pretty slick method ... realized this for myself not soo long ago.
Need to participate in the next golf challenge for improvement
_________________________



Top
#124410 - 2004-08-04 02:53 PM Re: Remove first and last Character
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
well, not fun for golf.
substr($string,2) is just as short as right($string,-1)
_________________________
!

download KiXnet

Top
#124411 - 2004-08-04 03:01 PM Re: Remove first and last Character
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
did not say my method was bullet proof. But, just to show it can be done.

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#124412 - 2004-08-04 03:07 PM Re: Remove first and last Character
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
me neither said it wasn't.
I just wanted to give some options...
your code looked so bloated first but then realized it was all that huge commenting that took all the space
_________________________
!

download KiXnet

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 (Henriques) and 2516 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.077 seconds in which 0.033 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