I have a simple python script like so:
import sys
lines = sys.argv[1]
for line in lines.splitlines():
print line
I want to call it from the command line (or a .bat file) but the first argument may (and probably will) be a string with multiple lines in it. How does one do this?
Of course, this works:
import sys
lines = """This...
I have a Gridview control on an ASP.Net page with fixed width cells. The data coming from the database occasionally comes over as a contiguous string of characters. When there are dashes in the string, it will break so as not to upset the width of the layout. If there are no dashes (specifically, I'm dealing with underscores), the string...
How can I format a number to a fixed number of decimal places (keep trailing zeroes) where the number of places is specified by a variable?
e.g.
int x = 3;
Console.WriteLine(Math.Round(1.2345M, x)); // 1.234 (good)
Console.WriteLine(Math.Round(1M, x)); // 1 (would like 1.000)
Console.WriteLine(Math.Round(1.2M, x)); // 1.2 (w...
Hi everyone,
I'm new to Java and I'm trying to achieve something pretty simple but I am not allowed to use regex... Which is my favorite tool to do that type of task.
Basically I need to make sure a string only contains alpha, numeric, space and dashes.
I found the class org.apache.commons.lang.StringUtils and the almost adequate meth...
Okay I have to write a program that accepts 2 or more arguments and searches the second and remaining arguments for a matching argument.
for example the output would be:
./a 3 h 4 9 3
3 found
or
./a hsi and iash me 34 hsi
hsi found
So far I have this, and I'm pretty sure I've got a lot of junk in here that is useless in the...
Given this code:
#include <iostream>
#include <vector>
#include <fstream>
#include <sstream>
#include <boost/regex.hpp>
using namespace std;
using namespace boost;
int main ( int arg_count, char *arg_vec[] ) {
if (arg_count !=2 ) {
cerr << "expected one argument" << endl;
return EXIT_FAILURE;
}
string ...
Sorry, todays silly question (and easy points) but whats the best way to convert a list(of string) to a string with the values seperated by ,
Sorry ....
...
I am trying to clean all of the HTML out of a string so the final output is a text file. I have some some research on the various 'converters' and am starting to lean towards creating my own dictionary for the entities and symbols and running a replace on the string. I am considering this because I want to automate the process and ther...
This simple solution popped into my mind quickly.
#include <ctype.h>
int digit_exists_in
(
const char *s
)
{
while (*s)
{
if (isdigit(*s))
{
return 1;
}
else
{
s++;
}
}
return 0;
}
int main(void)
{
int foundDigit = digit_exists_in("abcdefg...
Hi,
What's the current best practice for handling generic text in a platform independent way?
For example, on Windows there are the "A" and "W" versions of APIs. Down at the C layer we have the "_tcs" functions (like _tcscpy) which map to either "wcscpy" or "strcpy". And in the STL I've frequently used something like:
typedef std::ba...
I have been looking for an elegant and efficient way to chunk a string into substrings of a given length in Ruby.
So far, the best I could come up with is this:
def chunk(string, size)
(0..(string.length-1)/size).map{|i|string[i*size,size]}
end
>> chunk("abcdef",3)
=> ["abc", "def"]
>> chunk("abcde",3)
=> ["abc", "de"]
>> chunk("abc...
Is it possible to overload a method on default parameters?
For example, if I have a method split() to split a string, but the string has two delimiters, say '_' and "delimit". Can I have two methods something like:
split(const char *str, char delim = ' ')
and
split(const char *str, const char* delim = "delimit");
Or, is there a ...
As far as I know, strings are immutable in Delphi. I kind of understand that means if you do:
string1 := 'Hello';
string1 := string1 + " World";
first string is destroyed and you get a reference to a new string "Hello World".
But what happens if you have the same string in different places around your code?
I have a string hash assi...
What is the proper way to convert an XML URI into a Windows file path?
As a starting point, it's possible to turn:
file:///C:/DirA/DirB/File.txt
into:
C:\DirA\DirB\File.txt
... by first dropping the file:/// substring (having used it to determine we're dealing with a local file) and then placing a backslash wherever a slash appear...
How do I take four received data bytes and assemble them into a floating-point number?
Right now I have the bytes stored in an array, which would be, received_data[1] ... received_data[4]. I would like to store these four bytes as a single 32-bit single precision float.
-Thanks
I'm actually receiving a packet with 19 bytes in it and...
I tried to split data as below, but the error "dat.split is not a function" displays. Anyone know how can I solve this problem?
var dat = new Date("2009/12/12");
var r = dat.split('/');
...
I'll need to accept a string of 5 numbers from the user (only 5).
Should I use
istringstream
for the same ?
Can't I get away with something like this ?
int main()
{
char *InputMain;
InputMain=(char *)malloc(5+1);
cout << "Enter the number : " <<endl;
cin.getline ( InputMain, 5, '\n' ); // Input goes int...
I'm surprised there's not an overload that can take a string array. Anyway, what is the best way to avoid nesting calls to Path.Combine?
pathValue = Path.Combine(path1, Path.Combine(path2, Path.Combine(path3, path4)))
This seems inefficient since it results in 4 new strings being created just to get 1.
...
In std::string there are only const members to fetch the data like c_str(). However I can get a reference to the first element of the string via operator[] and I can write to it.
For example, if I have function:
void toupper(char *first,char *last_plus_one);
I can write directly to vector getting a pointer to the first element:
vect...
Is there a way to globally suppress the unicode string indicator in python? I'm working exclusively with unicode in an application, and do a lot of interactive stuff. Having the u'prefix' show up in all of my debug output is unnecessary and obnoxious. Can it be turned off?
...