I have a hierarchy of directories containing many text files. I would like to search for a particular text string every time it comes up in one of the files, and replace it with another string. For example, I may want to replace every occurrence of the string "Coke" with "Pepsi". Does anyone know how to do this? I am wondering if there is some sort of Bash command that can do this without having to load all these files in an editor, or come up with a more complex script to do it.
I found this page explaining a trick using sed, but it doesn't seem to work in files in subdirectories.
I have a String array in a Groovy class (args to a main method):
String[] args
I'd like to convert the 3rd to the last element into a new array of ints. Is there an easier way to do this in Groovy other than:
final int numInts = args.length - 2
final int [] intArray = new int[numInts]
for (int i = 2; i < args.length; i++) {
intArray[i-2]=Integer.parseInt(args[i])
}
I wanted to do:
final int numInts = args.length - 2
final int [] intArray = new int[numInts]
System.arraycopy(args, 2, intArray, 0, numInts)
But it throws a class cast exception.
Thanks!
Hi,
Is there any inbuilt way in C# to split a text into an array of words and delimiters?
What I want is:
text = "word1 + word2 - word3";
string[] words = text.Split(new char[] { '+', '-'});
//Need list '+', '-' here?
Any ideas? Obviously I can just process the text by hand... :)
I'm building a simple hex editor in C#, and I've decided to use each cell in a DataGrid to display a byte*. I know that DataGrid will take a list and display each object in the list as a row, and each of that object's properties as columns. I want to display rows of 16 bytes each, which will require a wrapper with 16 string properties. While doable, it's not the most elegant solution. Is there an easier way? I've already tried creating a wrapper around a public string array of size 16, but that doesn't seem to work.
Thanks
*The rational for this is that I can have spaces between each byte without having to strip them all out when I want to save my edited file. Also it seems like it'll be easier to label the rows and columns.
I have a large piece of text in which there is something simular to this:
!#_KT_#!COMMANDHERE!#_KT_#!
I want, in VB.Net, to get the 'COMMANDHERE' part of the string, how would I go about doing this? I have this so far:
Dim temp As String = WebBrowser1.Document.Body.ToString
Dim startIndex As Integer = temp.IndexOf("!#__KT__#!") + 1
Dim endIndex As Integer = temp.IndexOf("!#__KT__#!", startIndex)
Dim extraction As String = temp.Substring(startIndex, endIndex - startIndex).Trim
TextBox1.Text = extraction
However this only removes the LAST string eg: #_KT_#! COMMAND.
Any help is appreciated!
I have the following code:
// Form the continuities list
string[] continuities = new string[] { "10s", "20s", "30s" };
Model.Continuities = new SelectList(continuities, 2 );
I expect "20s" to be selected
How can I do that without creating a new class?
test = 'a'
test2 = '@a'.slice(0)
test3 = '@a'[1]
puts test.hash
puts test2.hash
puts test3.hash
Output:
100
64
97
Is this a bug or am I misunderstanding how the hash method works? Is there a way to fix this?
Hi,
I'm trying to use PHP to create a file containing a list of phone numbers.
It's working OK however if the phone number begins with zero, the digit is dropped from the excel file.
Does anyone know how to set the formatting correctly so that it remains in place?
Any advice appreciated.
Thanks.
This is for UNIX shell programming. It have to be supported by multiple UNIX platforms including Solaris, Linux, and AIX.
I have this scenario -- I am to read from a text file a string that may or may not contain an environment variable that may or may not be defined. For example:
<foo.bar> This error code was found: $(error_code)
I have the following code:
statement=$(sed -n $1'p' $messagefile)
echo $echo_flag $statement
$1 = line number supplied to this particular function/script.
$messagefile = filename of log file.
$echo_flag = "-e" in Linux, otherwise, empty.
$(error_code) = 42.
Instead of getting this when running:
<foo.bar> This error code was found: 42
I still get this:
<foo.bar> This error code was found: $(error_code)
How exactly do I tell the shell script that the value of statement should be evaluated further beyond what sed have done?
I want to modify csharp-mode.el so that it includes the appropriate error regex's (regexi?) for the .NET csc.exe compiler.
How should a well-behaved progmode do this?
In my code, I load up an entire folder into a list and then try to get rid of every file in the list except the .mp3 files.
import os
import re
path = '/home/user/mp3/'
dirList = os.listdir(path)
dirList.sort()
i = 0
for names in dirList:
match = re.search(r'\.mp3', names)
if match:
i = i+1
else:
dirList.remove(names)
print dirList
print i
After I run the file, the code does get rid of some files in the list but keeps these two especifically:
['00. Various Artists - Indie Rock Playlist October 2008.m3u', '00. Various Artists - Indie Rock Playlist October 2008.pls']
I can't understand what's going on, why are those two specifically escaping my search.
I need to throw ValidationError containing anchor.
if not profile.activated():
raise ValidationError('Your profile is not activated. <a href="{% url resend_activation_key %}">Resend activation key</a>.')
What I need to modify to make this work?
Hi all
I have a resources file called string.xml in res/valus directory
the file has many string resources
how can I obtain these items in an array from code ?
I tried
Field[] x=R.string.class.getFields();
but it does not work.
thanks
Should the playersToInvite property of the GKMatchRequest object contain an array of NSString objects that hold the player id's or should it contain an array of GKPlayer objects? The documentation on this critical property is not clear at all and I've tried both ways, but my code isn't working, so I can't tell by experimentation.
Here's the description for that property in the docs...
A list of players to invite to the
match.
Why did they even bother writing that?
Thanks for your help!
I'm thinking of building a Click-Once application, and am trying to wrap my head around how to handle the whole connection string issue. The problem is the following:
I want to use EF to get data directly from each client, thus requiring each client to have a connection string configured (this is not the issue). How do I deal with clients that are not on the same domain as the SQL Server being queried? In other words, if I tried to run my app from home as opposed to from work, what should my connection string look like? Would I need to configure my SQL Server differently to allow this scenario?
Thanks in advance!
I am trying to make a url by first collecting the parameters, and then in one statement creating the actual url. Here is what I am trying to do:
NSString *urlString = @"http://www.some_login_url.com?email=%@&password=%@";
NSString *email = self.email.text;
NSString *password = self.password.text;
NSString *url_to_send = [NSString stringWithFormat:@"%@%@", urlString , email , password];
So what I wanted to do was replace the @ symbols with the values in the variables, but instead the second variable just got appended to the end of the string.
How would I change the last line so I could put the right parameters in their correct spots?
Thanks!!
Background:
I'm trying to come up with a regex for a rewrite rule that will take anything that does not start with a particular prefix, and add that prefix to it. But urls that already have the prefix should be rejected by the regular expression (because they already have the url).
Example:
If the prefix is s1 a string like home will capture the home part. But a string like s1/home, will not capture anything.
This way I can add the capture group onto the prefix, so that 'home' will become 's1/home'.
I've tried (^s1/), but I'm missing something here, because that rejected 'home' for some reason.
I have:
int array_id;
char* records[10];
// get the shared segment
if ((array_id = shmget(IPC_PRIVATE, 1, 0666)) == -1) {
perror("Array Creating");
}
// attach
records[0] = (char*) shmat(array_id, (void*)0, 0);
if ((int) *records == -1) {
perror("Array Attachment");
}
which works fine, but when i try and detach i get an "invalid argument" error.
// detach
int error;
if( (error = shmdt((void*) records[0])) == -1) {
perror(array detachment);
}
any ideas? thank you
I want to remove hyphens (-), slashes (/) and white space () from a string name(i) so that I can use it as a structure field name.
This is the ugly way I am currently doing it using the function strrep:
cell2mat(strrep(strrep(strrep(name(i), '-',''),'/',''),' ', ''))
I have also tried other variations, such as:
strrep(name(i),{'-','/'},{'',''});
strrep(name(i),['-','/'],['','']);
What is a more efficient way of doing this?
I want to replace all instances of an specific words between braces with something else, unless it is written between double braces, while it should show as is it was written with single braces without the filter.
I have tried a code but only works for the first match. The rest are shown depending of the first one:
$foo = 'a {bar} b {{bar}} c {bar} d';
$baz = 'Chile';
preg_match_all( '/(\{?)\{(tin)\}(\}?)/i', $foo, $matches, PREG_SET_ORDER );
if ( !empty($matches) ) {
foreach ( (array) $matches as $match ) {
if( empty($match[1]) && empty($match[3])) {
$tull = str_replace( $match[0], $baz, $foo );
} else {
$tull = str_replace( $match[0], substr($match[0], 1, -1), $foo ) ;
}
}
}
echo $tull;
Say I have an environment variable myvar:
myvar=\tapple\n
When the following command will print out this variable
perl -e 'print "$ENV{myvar}"'
I will literally have \tapple\n, however, I want those control chars to be evaluated and not escaped. How would I achieve it?
In the real world $ENV residing in substitution, but I hope the answer will cover that.
In my native C+ Win32 GUI application I have a property sheet with two property pages. One of the property pages contains an edit box:
EDITTEXT IDC_EDIT_ID,x,y,width,height,ES_MULTILINE | ES_READONLY | NOT WS_BORDER | WS_VSCROLL | WS_HSCROLL | NOT WS_TABSTOP,WS_EX_STATICEDGE
I set a multiline text to this edit box. The text has more lines than the edit can fit, so some of the text is clipped and a vertical scroll bar appears.
When I scroll up with the mouse the lines that come "from under clip area" are drawn as garbage - it looks like first one line is drawn, then some other line is drawn on the same place without first painting the background. The lines that just move up - ones that were visible before scrolling and remain visible after scrolling are displayed allright.
What's the reason and workaround for this behavior?
I am new to xml and unable to find a way to get content in between tags.
My XML file is
<?xml version="1.0" encoding="utf-8"?>
<block1>
<file name="c:\w0.xml">
<word>Text</word>
<number>67</number>
</file>
<file name="c:\w1.xml">
<word>Text</word>
<number>67</number>
</file>
<file name="c:\w2.xml">
<word>Text</word>
<number>67</number>
</file>
</block1>