Globally replace text in several files: Difference between revisions
Content added Content deleted
Drkameleon (talk | contribs) (added Arturo) |
(Initial FutureBasic task solution added) |
||
Line 630: | Line 630: | ||
L0 += 1 |
L0 += 1 |
||
Wend</syntaxhighlight> |
Wend</syntaxhighlight> |
||
=={{header|FutureBasic}}== |
|||
<syntaxhighlight lang="futurebasic"> |
|||
include "NSLog.incl" |
|||
void local fn GloballyCreateAndReplaceFileText |
|||
NSUInteger i |
|||
CFURLRef url |
|||
CFMutableArrayRef mutURL = fn MutableArrayNew |
|||
CFArrayRef fileNames = @[@"file1", @"file2", @"file3"] |
|||
CFStringRef fileContentStr |
|||
CFStringRef originalText = @"Goodbye London!" |
|||
CFStringRef replacementText = @"Hello New York!" |
|||
for i = 0 to len(fileNames) - 1 |
|||
CFURLRef desktopURL = fn FileManagerURLForDirectory( NSDesktopDirectory, NSUserDomainMask ) |
|||
url = fn URLByAppendingPathComponent( desktopURL, fileNames[i] ) |
|||
url = fn URLByAppendingPathExtension( url, @"txt" ) |
|||
fn StringWriteToURL( originalText, url, YES, NSUTF8StringEncoding, NULL ) |
|||
MutableArrayAddObject( mutURL, url ) |
|||
next |
|||
NSLog( @"Original text:" ) |
|||
for i = 0 to len(mutURL) - 1 |
|||
fileContentStr = fn StringWithContentsOfURL( mutURL[i], NSUTF8StringEncoding, NULL ) |
|||
NSLog( @"Contents at: %@ = %@", fn URLPath( mutURL[i] ), fileContentStr ) |
|||
fn StringWriteToURL( replacementText, mutURL[i], YES, NSUTF8StringEncoding, NULL ) |
|||
next |
|||
NSLog( @"\nReplacement text:" ) |
|||
for i = 0 to len(mutURL) - 1 |
|||
fileContentStr = fn StringWithContentsOfURL( mutURL[i], NSUTF8StringEncoding, NULL ) |
|||
NSLog( @"Contents at: %@ = %@", fn URLPath( mutURL[i] ), fileContentStr ) |
|||
next |
|||
end fn |
|||
fn GloballyCreateAndReplaceFileText |
|||
HandleEvents |
|||
</syntaxhighlight> |
|||
{{output}} |
|||
<pre> |
|||
Original text: |
|||
Contents at: /Users/ken/Desktop/file1.txt = Goodbye London! |
|||
Contents at: /Users/ken/Desktop/file2.txt = Goodbye London! |
|||
Contents at: /Users/ken/Desktop/file3.txt = Goodbye London! |
|||
Replacement text: |
|||
Contents at: /Users/ken/Desktop/file1.txt = Hello New York! |
|||
Contents at: /Users/ken/Desktop/file2.txt = Hello New York! |
|||
Contents at: /Users/ken/Desktop/file3.txt = Hello New York! |
|||
</pre> |
|||
=={{header|Go}}== |
=={{header|Go}}== |