Jump to content

Not your average Copy/Paste


Recommended Posts

I need to copy a string of text from one document to another.
For starters file extension is not txt but it is a notepad class document.
I have about 3 strings of code I need to copy from 10 different documents and paste and overwrite
different strings in another document. Counting lines is not an option, however each string begins
and ends with an identifiable string.

Example: lets call this document test01.bs
SPolygonGeometry :local_15. {    
Every thing after and not including the line above
There is a bunch of code between that I need to copy and paste to another document
Everything before and not including the line below
    SPolygonGeometry.VertexData [ VertexDataVector2f :local_21 ];

Example: lets call this document test2.bs
SPolygonGeometry :local_55 . {
Everythig after and not including the line above
I need to paste and overwrite code from above document to here
Everything before and not including the line below
    SPolygonGeometry.VertexData [ VertexDataVector2f :local_61 ];

Selecting documents, creating inputs and all the rest isn't a problem.
If this was a simple copy paste I wouldn't need help.
Any ideas, examples would be great.

Thanks

Link to comment
Share on other sites

You Could Use FileReadtoArray and search for the string with StringInString, Use StringLeft,StringRight,StringMid to gather the needed data

Read the destination document with FileReadtoArray and replace the desired lines with your new lines and then use FileWritefromArray to save the modified destination file.

 
$aSource = FileReadToArray ( " test01.bs" ) 

$sStringStart = 'SPolygonGeometry :local_55 . {'
$sStringEnd = '}END' ;made it up :|

For $i = 0 to Ubound($aSource) - 1
  If StringInStr($aSource[$i], $sStringStart) Then
    $sCopyString = StringMid($aSource[$i], StringLen($sStringStart) - 1, _
      StringLen($aSource[$i]) - Int(StringLen($sStringStart) - 1) - int(StringLen($aSource[$i]) - StringInStr($aSource[$i], $sStringEnd) ) )
  EndIf ;you may have to adjust the StringLen Calls a bit
Next
$sStringStart2 = 'Whatever'

$aDestination = FileReadToArray ( " test02.bs" ) 
For $i = 0 to Ubound($aDestination) - 1
  If StringInStr($aDestination[$i], $sStringStart2) Then
    $aDestination[$i] = 'your replacement string here'
  EndIf 
Next
_FileWriteFromArray('New File.bs',$aDestination)

the above is a basic, untested, idea

Edited by Shane0000
Link to comment
Share on other sites

Maybe this.

If FileExists("test01.bs") Then
    FileDelete("test01.bs")
    FileWrite("test01.bs", _
            "Example: lets call this document test01.bs" & @CRLF & _
            "SPolygonGeometry :local_15. {" & @CRLF & _
            "Every thing after test01.bs and not including the line above" & @CRLF & _
            "There is a bunch of code between that I need to copy and paste to another test01.bs document" & @CRLF & _
            "Everything test01.bs before and not including the line below" & @CRLF & _
            "   SPolygonGeometry.VertexData [ VertexDataVector2f :local_21 ];" & @CRLF & _
            "This is test01.bs.")
EndIf
If FileExists("test2.bs") Then
    FileDelete("test2.bs")
    FileWrite("test2.bs", _
            "Example: lets call this document test2.bs" & @CRLF & _
            "SPolygonGeometry :local_55 . {" & @CRLF & _
            "Everythig after test2.bs and not including the line above" & @CRLF & _
            "I need to paste and overwrite code test2.bs from above document to here" & @CRLF & _
            "Everything before and not test2.bs including the line below" & @CRLF & _
            "    SPolygonGeometry.VertexData [ VertexDataVector2f :local_61 ];" & @CRLF & _
            "This is test2.bs.")
EndIf

; Get string from "test01.bs"
Local $aSource = FileRead("test01.bs")
Local $sStringStart = 'SPolygonGeometry :local_15. {'
Local $sStringEnd = '   SPolygonGeometry.VertexData [ VertexDataVector2f :local_21 ];' ;made it up :|
Local $sStringCopy = StringRegExpReplace($aSource, '(?is)^.*?\Q' & $sStringStart & '\E(.+?)\Q' & $sStringEnd & '\E.*$', "\1")
;ConsoleWrite($sStringCopy & @LF)

;Replace string in "test2.bs" with the string got from "test01.bs".
Local $aSource2 = FileRead("test2.bs")
Local $sStringStart2 = 'SPolygonGeometry :local_55 . {'
Local $sStringEnd2 = ' SPolygonGeometry.VertexData [ VertexDataVector2f :local_61 ];' ;made it up :|
Local $sStringReplace = StringRegExpReplace($aSource2, '(?is)(^.*?\Q' & $sStringStart2 & '\E)(.+?)(\Q' & $sStringEnd2 & '\E.*$)', "\1" & $sStringCopy & "\3")

FileDelete("test2.bs")
FileWrite("test2.bs", $sStringReplace)

ConsoleWrite(FileRead("test2.bs") & @LF)
#cs
"test2.bs" now contains:-
Example: lets call this document test2.bs
SPolygonGeometry :local_55 . {
Every thing after test01.bs and not including the line above
There is a bunch of code between that I need to copy and paste to another test01.bs document
Everything test01.bs before and not including the line below
 SPolygonGeometry.VertexData [ VertexDataVector2f :local_61 ];
This is test2.bs.
#ce
Link to comment
Share on other sites

Malkey

Not having any luck, it just copies text from if statement and deletes everything else.

The two "If" statements are actually just creating the two document type files, "test01.bs" and "test2.bs" for script's testing purposes.

Are you saying that you don't get "test2.bs" file containing the text within the "#cs..#ce", block comment which is at the end of my example script?

Or, if "test2.bs" file does contain the text within the block comment, this is not what you want to happen - not what you are after?

 

Link to comment
Share on other sites

It's kind of hard for me to explain. I think it would be easier if you looked at some of the code I'm trying to copy.

I'm attaching a document with a small bit of the code and a few notes.

Open it in notepad take a look and tell me what you think.

Edited by Melba23
Attachment removed
Link to comment
Share on other sites

Hi there,

Is this related with gaming mod?

Cheers

Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

Link to comment
Share on other sites

However it's up to the moderators to interpret the forum rules, so I advise caution.

I was thinking along the same lines. Although I consider any script that makes any game 'easier' or 'more efficient' to fall into the No Game Automation category, I am slightly biased. I feel that the business world has tainted games in pretty much the same way it has tainted the music world..

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Link to comment
Share on other sites

I was thinking along the same lines. Although I consider any script that makes any game 'easier' or 'more efficient' to fall into the No Game Automation category, I am slightly biased. I feel that the business world has tainted games in pretty much the same way it has tainted the music world..

 

It remains to be seen if any advantage can be made of the mods. If so then such an advantage may be considered unfair. However there are many open source projects which sometimes offer tools to customize your gaming experience. Here the distinction gets somewhat vague.

@trashy: What game is it?

Edited by czardas
Link to comment
Share on other sites

It remains to be seen if any advantage can be made of the mods. If so then such an advantage may be considered unfair. However there are many open source projects which sometimes offer tools to customize your gaming experience. Here the distinction gets somewhat vague.

@trashy: What game is it?

 

The game is The Klub 17.

Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

Link to comment
Share on other sites

  • Moderators

trashy,

Having looked at "The Klub 17" I can tell you categorically that we are not prepared to have anything to do with it - thread locked. :naughty:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...