string

Automated acronym creation

Is there any easy way to create an acronym from a string? First_name Middle_name Last_name => FML first_name middle_name last_name => FML First_name-Middle_name Last_name => F-ML first_name-middle_name last_name => F-ML ...

How do I print the full value of a long string in gdb?

I want to print the full length of a C-string in GDB. By default it's being abbreviated, how do I force GDB to print the string in full? ...

Splitting strings in python

I have a string which is like this: this is [bracket test] "and quotes test " I'm trying to write something in Python to split it up by space while ignoring spaces within square braces and quotes. The result I'm looking for is: ['this','is','bracket test','and quotes test '] ...

Upper vs Lower Case

When doing case-insensitive comparisons, is it more efficient to convert the string to upper case or lower case? Does it even matter? It is suggested in this SO post that C# is more efficient with ToUpper because "Microsoft optimized it that way." But I've also read this argument that converting ToLower vs. ToUpper depends on what you...

What's the best way to have stringTokenizer split up a line of text into predefined variables

I'm not sure if the title is very clear, but basically what I have to do is read a line of text from a file and split it up into 8 different string variables. Each line will have the same 8 chunks in the same order (title, author, price, etc). So for each line of text, I want to end up with 8 strings. The first problem is that the last ...

What is std::safe_string?

An answer to one of my questions included the following line of code: label = std::safe_string(name); // label is a std::string The intent seems to be a wrapper around a string literal (so presumably no allocation takes place). I've never heard of safe_string and neither, apparently, has google (nor could I find it in the 98 standard)...

How can I support wildcards in user-defined search strings in Python?

Is there a simple way to support wildcards ("*") when searching strings - without using RegEx? Users are supposed to enter search terms using wildcards, but should not have to deal with the complexity of RegEx: "foo*" => str.startswith("foo") "*foo" => str.endswith("foo") "*foo*" => "foo" in str (it gets more complicated when...

How to output a String on multiple lines using Graphics

My Program overrides public void paint(Graphics g, int x, int y); in order to draw some stings using g.drawString(someString, x+10, y+30); Now someString can be quite long and thus, it may not fit on one line. What is the best way to write the text on multiple line. For instance, in a rectangle (x1, y1, x2, y2)? ...

Python file interface for strings

Is there a Python class that wraps the file interface (read, write etc.) around a string? I mean something like the stringstream classes in C++. I was thinking of using it to redirect the output of print into a string, like this sys.stdout = string_wrapper() print "foo", "bar", "baz" s = sys.stdout.to_string() #now s == "foo bar baz" ...

Java performance of StringBuilder in a loop

I've a performance related question regarding use of StringBuilder. In a very long loop I'm manipulating a StringBuilder and passing it to another method like this: for (loop condition) { StringBuilder sb = new StringBuilder(); sb.append("some string"); . . . sb.append(anotherString); . . . passToMethod(sb.toStri...

c# - What is string really good for?

Hi, I've tried reading a JPG file using the StreamReader class' ReadToEnd() method which returns a string. For some reason though, when I write this string out to a file, it doesn't open. Is something lost when reading data into a string? What is it really good for? If I use a byte array and read into that then its fine. ...

Long strings

Hey! I have seen c# code that uses the @ to tell the compiler the string has newlines in it and that it should be all in one line. Is there something like that for c/c++? Like if I want to put something like: 73167176531330624919225119674426574742355349194934 96983520312774506326239578318016984801869478851843 85861560789112949495459501...

How do i split a String into multiple values?

How do you split a string? Lets say i have a string "dog, cat, mouse,bird" My actual goal is to insert each of those animals into a listBox, so they would become items in a list box. but i think i get the idea on how to insert those items if i know how to split the string. or does anyone know a better way to do this? im using asp c# ...

Is there an alternative to string.Replace that is case-insensitive?

I need to search a string and replace all occurances of %FirstName% and %PolicyAmount% with a value pulled from a database. The problem is the capitalization of FirstName varies. That prevents me from using the String.Replace() method. I've seen web pages on the subject that suggest Regex.Replace(strInput, strToken, strReplaceWith, Rege...

Howto initialise char array style string in constructor

I have a class which I'm serialising to send over a unix socket and it has to have a string which I've stored as a char array. Can I initialise it in the constructor differently to how I've done it here? typedef struct SerialFunctionStatus_t { SerialFunctionStatus_t() : serial_rx_count(0), serial_tx_count(0), socket_rx_cou...

how to convert tis-620 string to utf-8 string in java

how to convert tis-620 string to utf-8 string in java ...

Algorithm to find similar text

I have many articles in a database (with title,text), I'm looking for an algorithm to find the X most similar articles, something like Stack Overflow's "Related Questions" when you ask a question. I tried googling for this but only found pages about other "similar text" issues, something like comparing every article with all the others...

'\0' related problem..

Looking at this loop that copies one c-string to another: void strcpyr(char *s, char *t) { while(*s++=*t++)// Why does this work? ; } Why do we not check for the '\0' character in the while loop, like this? while((*s++=*r++)!='\0').. How does the first loop terminate? ...

How do I turn a String into a Stream in java?

I need to transform a string into (finally) an InputStreamReader. Any ideas? ...

JavaME: Convert String to camelCase

What would be a simple implementation of a method to convert a String like "Hello there everyone" to "helloThereEveryone". In JavaME support for String and StringBuffer utility operations are quite limited. ...