Sign in to follow this  
Followers 0
t0ddie

string replace

10 posts in this topic

hello. im trying to take random size lines, and erase certain parts from it.

i have a .txt document with this.

**: k2#ldk, coolness

**: Skf%6rk, ahah4haa

**: ppppp, bo)g

and i want to make it look like this.

k2#ldk coolness

Skf%6rk ahah4haa

ppppp bo)g

this list is constantly being added to.. and the size of each line is random.

otherwise i would use string replace. stringtrim. i look a few things up.

plus, i want to keep the space after the comma, but not the space after the colon:

im pretty sure this is do-able, but i dont even know where to START.

thanks for readin!

~Todd


Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Share this post


Link to post
Share on other sites



Hey t0ddie...

I am assuming the **: indicates a screen name of some sort?

Because if it isnt then this is simple. You just trim the left side. Otherwise we have a slightly bigger problem, but I am sure you can do it as well.

JS


AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Share this post


Link to post
Share on other sites

Umm, Have you tried StringReplace($str, ", ", " ") ? or maybe StringTrimLeft($str, StringInStr($str, ": ") + 1) ?


Who else would I be?

Share this post


Link to post
Share on other sites

yes i tried all of those.

and **: doesnt mean anything. that whole asterisk asterisk colon space can go. thats the easy part.

just trim 4 from the left.

the problem lies here...

k2#ldk, coolness.. o wait, thats not a problem at all!

(I JUST HAD A BRAIN FART)

just string replace "," with ""

i cant beleive how easy that is.. and that i didnt catch that before.

thanks for leading me in the right direction. i figured it out! without even sample code!

before the problem was.. because i didnt know how long each string is.. on either side of the comma and space.. because it is a different size every time.. i was confuzzled

but yeah. you all are AWESOME. thanks for the quick reply!


Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Share this post


Link to post
Share on other sites

heres the code, untested.. but im confident that it will work

StringTrimLeft($bak,4)

StringReplace($bak,",","",,)

other than that... slightly off topic.

has anyone written a script that will match each line in a file... and erase copies of the same line?

so if this came up

hjhjh hhjhjhjh

fun fool

sdjikpodsf

sdfjhklhsdf

jhqerlwerlolhiwe

fun fool

werujhiose

heo

it would look like this

hjhjh hhjhjhjh

fun fool

sdjikpodsf

sdfjhklhsdf

jhqerlwerlolhiwe

werujhiose

heo

thanks!


Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Share this post


Link to post
Share on other sites

hey toddie,

I have written a script ( with the help of these people in the forum) that constantly adds usernames to a txt file but first checks if it alreadyy exists before adding...

I'm on a public computer right now so i think ill post when i get home. In the mean time, try it a bit yourself, thats how you learn.

This should get you started: try reading the list into an array to start with and continue to add it in that array as you go along (Ubound is key in this script) then write it in the txt file as well. As you are adding new values, check that new item against the whole array. this of course involves the use of a loop. Within the loop make a counter that counts how many times the new item is different from the old items. If the counter is equal to the number of items at the end of the loop (does not already exist) add it in the array (ReDIm) and the txt file as well and loop it!

hope it helped, iwill post my script later but i find you understand better if you try it yourself first

:ph34r: -Fryboy


Roger! You son of a big pile o' Monkey Nuts.

Share this post


Link to post
Share on other sites

makes sense.

i look forward to your posting :ph34r:

thanks. that was insightful.


Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Share this post


Link to post
Share on other sites

well, i got it to work, had to change it slightly

$bak = ClipGet()

$bak = StringTrimLeft($bak,4)

$bak = StringReplace($bak,",","")

$file = FileOpen("TEST.txt", 1)

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

thats her. isnt she pretty?

not that its a huge deal.... but

with an empty .txt file.. it wont write to the first line.

what i mean is... that when the .txt file is empty, it will make a "blank" line (empty)

(looks like a carriage return was performed first) before printing the line. it always starts on the second line.

i can put some text in the first line, and that doesnt effect it. it still starts on the second line, like it should.. but not on the third line like i would expect because of the previous mentioned circumstance.

so i dont know what the deal is. it only does this if the .txt file is EMPTY

every other line writes fine.. with no "blank" lines between lines. just the first line always is blank.

just thought that was interesting.. and was wondering if there is a reason for it? or if i found a bug? or if my coding is messed up? (usually is)

well, have a look at it if ya want fellas.

~Todd


Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Share this post


Link to post
Share on other sites

You do realize that:

  • You never write to the file, you only open it for appending.
  • You never close the file handle when you are done with it (Unrelated, but still something you should do).

Share this post


Link to post
Share on other sites

actually i do both.. i just didnt include that part of the script in this post.

but good looking out!

~Todd


Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0