string

Regex: How to match a string that contains repeated pattern ?

Is there a regex pattern that will match a string that contains repeated pattern, e.g.: "a"|"b","c"|"d",...,"y"|"z" Do you have any idea? Thanks. ...

How to split a text file into words?

Hello, I am working on a assignment where I am supposed to read a file and count the number of lines and at the same time count the words in it. I tried a combination of getline and strtok inside a while loop, which did not work. file:example.txt (the file to be read). Hi, hello what a pleasant surprise. Welcome to this place. M...

Is there an elegant work around to concatenation?

I am writing a mad libs program for fun and to just program something. The program itself is pretty straight forward, but I find myself resorting to several concatenations due to the nature of the game where you place user given words into a sentence. Is there an elegant work around to resort to less concatenations or even eliminate them...

Why switch statement cannot be applied on strings?

int main() { switch(std::string("raj")) //Compilation error - switch expression of type illegal { case"sda": } } ...

How to do std::string indexof in C++ that returns index of matching string?

I'm looking for a string indexof function from the std namespace that returns an integer of a matching string similar to the java function of the same name. Something like: std::string word = "bob"; int matchIndex = getAString().indexOf( word ); where getAString() is defined like this: std::string getAString() { ... } ...

Escaping verbatim string literals

I have the following string which won't compile: String formLookupPull = @"SELECT value1, '"+tableName+"', '"+columnName+"' FROM lkpLookups WHERE ""table"" = '" + tableName + "' and ""field"" = '" + columnName + "';"; The offending sections are : ""table"" = and ""field"" = THe compiler is getting all mixed up on the escape seq...

Are quotes a type of string delimiter? Or does 'delimiter' mean other types of characters not including quotes?

When people talk about string delimiters, does that include quotes or does that mean everything except quotes? ...

Is 'mutable' the same as the word 'modifiable' in relation to strings?

When we talk about strings as being mutable, is this synonymous with using the word 'changeable' or 'modifiable' or is there some additional nuance to explain why this jargon is used instead of a simpler word like 'modifiable'? ...

Effective way to iteratively append to a string in Python?

I'm writing a Python function to split text into words, ignoring specified punctuation. Here is some working code. I'm not convinced that constructing strings out of lists (buf = [] in the code) is efficient though. Does anyone have a suggestion for a better way to do this? def getwords(text, splitchars=' \t|!?.;:"'): """ Genera...

What is the most efficient way to convert an int to a String?

Say I have: int someValue = 42; Now I want to convert that int value to a String. Which way is more efficient? // One String stringValue = Integer.toString(someValue); // Two String stringValue = String.valueOf(someValue); // Three String stringValue = someValue + ""; I am just curious if there is any real difference or one is be...

In Sql Server, how to convert binary strings to binary?

I have some data in string format that represents binary data (e.g. '0x0002'). Is there some function or trick where I can convert these from literal strings to binary? That is, I want '0x0002' to become 0x0002, and SELECT CAST('0x0002' AS BINARY(20)) obviously won't do that. I did come up with some painfully slow process that involve...

Is 'buggy_logger' a reference to the 'status' string in this Ruby example?

In this example, do the nukes get launched because any changes that you make to buggy_logger get applied to the 'status' string - just like using a copy of a reference to an object -> when you make a change to the copy of the reference, the change gets applied to the underlying object -> that change is, in turn, reflected in any other re...

Aren't modern computers powerful enough to handle Strings without needing to use Symbols (in Ruby)

Every text I've read about Ruby symbols talks about the efficiency of symbols over strings. But, this isn't the 1970s. My computer can handle a little bit of extra garbage collection. Am I wrong? I have the latest and greatest Pentium dual core processor and 4 gigs of RAM. I think that should be enough to handle some Strings. ...

Trim a string in C

Briefly: I'm after the equivalent of .NET's String.Trim in C using the win32 and standard C api (compiling with MSVC2008 so I have access to all the C++ stuff if needed, but I am just trying to trim a char*). Given that there is strchr, strtok, and all manner of other string functions, surely there should be a trim function, or one t...

Why does "?b" mean 'b' in Ruby?

"foo"[0] = ?b # "boo" I was looking at the above example and trying to figure out: How "?b" implies the character 'b'? Why is it necessary? - Couldn't I just write this: "foo"[0] = 'b' # "boo" ...

How to assign a String from a text file into integer array for Java?

How to assign a String from a text file into integer array for Java? I had saved the integer array into a text file, but now how can I retrieve all the integer array from the text file without any modification? I want the integer array retrieved same as before it stored into the text file. Below is part of my code: BufferedWriter f1 = n...

How to find common strings among two very large files?

I have two very large files (and neither of them would fit in memory). Each file has one string (which doesn't have spaces in it and is either 99/100/101 characters long) on each line. Update: The strings are not in any sorted order. Update2: I am working with Java on Windows. Now I want to figure out the best way to find out all the s...

How can I use pointers to display strings in an array?

I am practicing using pointers. I have a pointer to an array of 3 strings: "dog", "cat", "rat". I can print the contents using a for loop and using an array. However, I am having problems printing them using pointer arithmetic. I would like to increment the pointer to the next element in the array. However, all it does is print the d...

Reading lots of characters and updating a textbox

I am reading data from a stream (provided by a process) character by character and adding it to a textbox so the user can see. The only problem is, this is SLOW. The user needs to see the data as it is given to the program (with little to no delay). I would like something like how terminals handle text, it can scroll by so fast that it's...

How do I concatenate multiple C++ strings on one line?

C# has a syntax feature where you can concatenate many data types together on 1 line. string s = new String(); s += "Hello world, " + myInt + niceToSeeYouString; s += someChar1 + interestingDecimal + someChar2; What would be the equivalent in C++? As far as I can see, you'd have to do it all on separate lines as it doesn't support mul...