string

Passing a multi-line string as an argument to a script in Windows

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...

force breaking a string in a fixed width Gridview cell

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 do I format a Decimal to a programatically controlled number of decimals in c#?

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...

Java String contains only...

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...

how to search arguments to find a match to the first argument in c language?

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...

Compiling C++ Code With Boost's regex_match

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 ...

Convert List to 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 .... ...

How to work with unicode in Python

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...

What is the fastest way to decide if a digit appears in a string?

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...

Cross-Platform Generic Text Processing in C/C++

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...

What is the best way to chop a string into chunks of a given length in Ruby?

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...

Overloading a method on default arguments

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 ...

Are Delphi strings immutable?

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...

Producing a Windows Path from an XML URI

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...

Parse four bytes to floating-point in C

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...

Splitting strings in JavaScript

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('/'); ...

Need user to input string /check string length (C++)

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...

Why does IO.Path.Combine only take 2 arguments?

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. ...

Is it legal to write to std::string?

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...

Suppress the u'prefix indicating unicode' in python strings

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? ...