Sign in to follow this  
Followers 0
CodyBarrett

Stringreplace

10 posts in this topic

im pretty sure i've posted something like this before but cannot find where...

alright what im trying to do..

i have a chatroom that runs off of a file.. multiple PCs use this one file.. and its read often, and im working on a Personalmessenger which is Easy with TCP.. but somehow more difficult using a file

the way it works..

Runs app > reads file(Currently hex format) > hextostring(File) > Stringsplit (@CRLF) > and then

For $i = 1 to stringsplit value

guictrlsetdata (main edit, stringsplit value[$i])

next

and that works fine.. just when i start adding Pm's that i don't want others to view... the pm type looks like this

"º!Name Message-From*º"

now if it isn't your PM.. the app replaces this as "" in the Main edit control....

trouble is.. if it IS your PM... i want it to replace the pm string in the file and rewrite it with the string removed.... i have this.. and its not working would anyone know how to do it? _stringreplaceinfile or whatever its called doesn't work because file is written in Hex

$File = FileRead($S_TXT)
            $File = _HexToString($File)
            $File = StringSplit($File, 'º')
            For $i = 1 To $File[0]
                If StringInStr($File[$i], '!' & $Name_S) Then
                    $Pm = _StringBetween($File[$i], '!' & $Name_S, '-')
                    $From = _StringBetween($File[$i], '-', '*')
                    $sFile = FileRead($S_TXT)
                    $sFile = _HexToString($sFile)
                    $sFile = StringReplace($sFile, @CRLF & 'º!' & $Name_S & _StringBetween ($File[$i], $Name_S, '*º') & '*º' & @CRLF, '')
                    $sFile = _StringToHex($sFile)
                    FileDelete($S_TXT)
                    FileWrite($S_TXT, $sFile)
                    MsgBox (0,'', $Pm[0])
                EndIf
                If StringLeft($File[$i], 1) = '!' Then $File[$i] = ''
                If StringLeft($File[$i], 1) = '$' Then $File[$i] = ''
                If StringLeft($File[$i], StringLen($Ignore)) = $Ignore Then $File[$i] = ''
                GUICtrlSetData($Main, GUICtrlRead($Main) & $File[$i])
            Next

any ideas? i've been stuck on this for a few weeks now but been to busy with other projects to post until now

Share this post


Link to post
Share on other sites



post an example of what's your file like, showing how u want change it

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

_StringBetween returns an array.

$File = FileRead($S_TXT)
            $File = _HexToString($File)
            $File = StringSplit($File, 'º')
            For $i = 1 To $File[0]
                If StringInStr($File[$i], '!' & $Name_S) Then
                    $Pm = _StringBetween($File[$i], '!' & $Name_S, '-')
                    $Pm = $Pm[0]
                    $From = _StringBetween($File[$i], '-', '*')
                    $From = $From[0]
                    $sFile = FileRead($S_TXT)
                    $sFile = _HexToString($sFile)
                    $Msg = _StringBetween ($File[$i], $Name_S, '*º')
                    $sFile = StringReplace($sFile, @CRLF & 'º!' & $Name_S & $Msg[0]  & '*º' & @CRLF, '')
                    $sFile = _StringToHex($sFile)
                    FileDelete($S_TXT)
                    FileWrite($S_TXT, $sFile)
                    MsgBox (0,'', $Pm[0])
                EndIf
                If StringLeft($File[$i], 1) = '!' Then $File[$i] = ''
                If StringLeft($File[$i], 1) = '$' Then $File[$i] = ''
                If StringLeft($File[$i], StringLen($Ignore)) = $Ignore Then $File[$i] = ''
                GUICtrlSetData($Main, GUICtrlRead($Main) & $File[$i])
            Next

I think this should work...

EDIT: Edited in my double post xD

Edited by toonboon

[right]~What can I say, I'm a Simplistic person[/right]

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

lmao i hate double posts.. happens to me all the time... alright here is what the .txt is like..

NORMAL text.. how i see it in the Chat

Global Message < Test > | < barrettc > Has Connected !

Test > Test

and now what the .txt looks like

0D0ABA476C6F62616C204D657373616765203C2054657374203E207C203C206261727265747463203E202048617320436F6E


6E65637465642021BA0D0A0D0ABA546573742020203E2020202054657374BA0D0A0D0ABA476C6F62616C204D657373616765


203C2054657374203E2048617320446973636F6E6E6563746564202EBA0D0A

EDIT

it doesn't even work when i use Stringmid() _stringbetween() i know it uses an array

Edited by CodyBarrett

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

lmao i hate double posts.. happens to me all the time... alright here is what the .txt is like..

NORMAL text.. how i see it in the Chat

and now what the .txt looks like

0D0ABA476C6F62616C204D657373616765203C2054657374203E207C203C206261727265747463203E202048617320436F6E




6E65637465642021BA0D0A0D0ABA546573742020203E2020202054657374BA0D0A0D0ABA476C6F62616C204D657373616765




203C2054657374203E2048617320446973636F6E6E6563746564202EBA0D0A

EDIT

it doesn't even work when i use Stringmid() _stringbetween() i know it uses an array

what should be replaced?, I saw in your script that u search for '-' but I can't see it anywhere in your txt example Edited by oMBRa

Share this post


Link to post
Share on other sites

im looking to replace everything from the PM with ""

like

!Tothem Mymessage-Frommyname* -----> ""

but to save it and view it later on when the user wants.... like i said its MUCH easyer with TCP and im kinda thinking ofjust excluding this from the app

Share this post


Link to post
Share on other sites

sorry but I still dont understand what your file looks like... first u said it is like this:

ºGlobal Message < Test > | < barrettc > Has Connected !º

ºTest > Testº

ºGlobal Message < Test > Has Disconnected .º

now u said

!Tothem Mymessage-Frommyname*

Share this post


Link to post
Share on other sites

this is what the File is in...

0D0ABA476C6F62616C204D657373616765203C2054657374203E207C203C206261727265747463203E202048617320436F6E

6E65637465642021BA0D0A0D0ABA546573742020203E2020202054657374BA0D0A0D0ABA476C6F62616C204D657373616765

203C2054657374203E2048617320446973636F6E6E6563746564202EBA0D0A

this is what the hextostring gives

ºGlobal Message < Test > | < barrettc > Has Connected !º

ºTest > Testº

and this is waht i see on the main Edit

Global Message < Test > | < barrettc > Has Connected !

Test > Test

this is an exxample of the PM... IN the File

º!ToName Message-FromName*º

it strips the "º" somewhere else in the script

Share this post


Link to post
Share on other sites

u mean something like this ?

#include <String.au3>
$String = 'BA21546F4E616D65204D6573736167652D46726F6D4E616D652ABA'
$String = 'example'&@CRLF&'º!ToName Message-FromName*º'&@CRLF&'example2'&@CRLF&'º!ToName Message-FromName*º'&@CRLF&'example3'
$String = _StringToHex($String)
$String = _HexToString($String)
$String = StringRegExpReplace($String, 'º!.+\*º', '')
MsgBox(0, '', $String)

Share this post


Link to post
Share on other sites

that above seems to work... ima look into regexreplace.... lol thanks

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