The tag has no wiki summary.

learn more… | top users | synonyms

43
votes
11answers
43k views

SQL: empty string vs NULL value

I know this subject is a bit controversial and there are a lot of various articles/opinions floating around the internet. Unfortunatelly, most of them assume the person doesn't know what the ...
32
votes
4answers
2k views

Etymology of “String”

So it's obvious that a string of things is a sequence of things, and so a sequence of characters/bytes/etc. might as well be called a string. But who first called them strings? And when? And in what ...
20
votes
5answers
2k views

Why are strings so slow?

Ever since my very first programming class in high school, I've been hearing that string operations are slower — i.e. more costly — than the mythical "average operation." Why makes them so ...
18
votes
2answers
5k views

Why does Java use UTF-16 for internal string representation?

I would imagine the reason was fast, array like access to the character at index, but some characters won't fit into 16 bits, so it wouldn't work... So if you have to handle special cases anyways, ...
14
votes
5answers
6k views

Should a string constant be defined if it's only going to be used once?

We're implementing an adapter for Jaxen (an XPath library for Java) that allows us to use XPath to access the data model of our application. This is done by implementing classes which map strings ...
11
votes
3answers
2k views

How many strings are created in memory when concatenating strings in Java?

I was asked about immutable strings in Java. I was tasked with writing a function that concatenated a number of "a"s to a string. What I wrote: public String foo(int n) { String s = ""; for ...
11
votes
2answers
333 views

How to select a most probable option from the list based on user text Input

I am working over a OCR Application where I need to select a option based on user text input. Ex: Available Options: ["python", "ruby", "java", "clojure", "haskell"] Input: kava Output: java Input: ...
10
votes
6answers
896 views

What are the pros and cons of having a CaseInsensitiveString type in Java?

I'm tempted to create a final class CaseInsensitiveString implements CharSequence. This would allow us to define variables and fields of this type, instead of using a regular String. We can also have ...
10
votes
6answers
2k views

Is it inefficient to concatenate strings one at a time?

I recall back from my days of programming in C that when two strings are joined, the OS must allocate memory for the joined string, then the program can copy all the string text over to the new area ...
9
votes
4answers
709 views

How defensive should we be?

We've been running Pex over some code, and it has been showing some good things (well bad things, but showing them before it gets to production!). However, one of the nice things about Pex is that it ...
9
votes
2answers
747 views

Why are Python strings allocated on the stack?

According to this Python code visualizer, Python strings are allocated on the stack and not on the heap. Why is this? I thought they would be similar to Java where Strings are allocated on the heap.
8
votes
5answers
4k views

How can I extract words from a sentence and determine what part of speech each is? [closed]

I want to write something that takes a sentence and identifies each word it contains and defines what part of speech each word is. For example Hello World, I am a sentence would return this ...
8
votes
1answer
2k views

How does PHP internally represent strings?

UTF8? UTF16? Do strings in PHP also keep track of the encoding used? Let's look at this script for example. Say I run: $original = "शक्नोम्यत्तुम्"; What actually happens? Obviously I think ...
8
votes
1answer
278 views

Match two strings but allow for a degree of error

How can I match two strings, but at the same time allow for X number of characters to be incorrect in the match. The number of errors should be a controllable variable. While X number of characters ...
8
votes
1answer
781 views

Possible Damerau-Levenshtein improvement?

I recently implemented the Damerau-Levenshtein distance algorithm from the pseudocode on Wikipedia. I couldn't find any explanation of exactly how it works and the pseudocode uses completely ...
7
votes
2answers
12k views

When should I use StringBuilder or StringBuffer?

In a production web application, my fellow programmers used StringBuffer everywhere. Now I am taking care of application development and corrections. After reading StringBuilder and StringBuffer I ...
7
votes
1answer
3k views

Shortest Common Superstring: find shortest string that contains all given string fragments

Given some string fragments, I would like to find the shortest possible single string ("output string") that contains all the fragments. Fragments can overlap each other in the output string. ...
7
votes
3answers
463 views

Longest subsequence without string

Does there exist a dynamic programming algorithm to find the longest subsequence in a string X that does not contain Y as substring? Just that this problem seems so similar to other DP string ...
6
votes
3answers
3k views

What performance can we expect from std::string's c_str()? Always constant time?

I've been doing some needed optimizations lately. One thing I've been doing is changing some ostringstreams -> sprintfs. I'm sprintf'ing a bunch of std::strings to a c style array, ala char foo[500]; ...
6
votes
11answers
523 views

What should I call the process of converting an object to a string?

We are having a game of 'semantic football' in the office over this matter: I am writing a method for an object which will represent the object as a string. That string should be such that when typed ...
6
votes
4answers
627 views

Should functions of a C library always expect a string's length?

I'm currently working on a library written in C. Many functions of this library expect a string as char* or const char* in their arguments. I started out with those functions always expecting the ...
6
votes
4answers
57k views

Initializing char array with string

I don't remember how I got to the thread, but I was reading its replies and one of them states that you should never initialize a char[] with a string literal. My question: Is initializing a ...
6
votes
2answers
5k views

Which string search algorithm is actually the fastest?

I have been stuck for some time on which is the fastest string search algorithm, heard many opinions, but in the end I'm not sure. I have heard some people saying that the fastest algorithm is ...
6
votes
5answers
3k views

Alternate string formatting options in C++?

I'm looking at optimizing some string formatting code that's hit a lot in our code. We had been using ostringstream, and I converted the code to use sprintf (actually Microsoft's more secure ...
6
votes
1answer
417 views

Finding occurrences of a useful words and phrases in strings

I am building an app that analyzes posts by people by pulling their Tweets and Facebook posts. I need to process all the posts and find useful phrases. What I mean by useful is that, any word or ...
6
votes
2answers
804 views

Complex string matching with fuzzywuzzy

I'm attempting to write a process that matches obscure strings to a single 'master string' for further processing. I have a lot of data that looks something like this: Basketball Basket Ball Football ...
6
votes
2answers
224 views

Index independent character comparison within text blocks

I have the following task: developing a program where there is a block of sample text which should be typed by user. Any typos the user does during the test are registered. Basically, I can compare ...
5
votes
6answers
11k views

string.format with variables vs inline variables

What are the pros/cons (if any) to using string output; int i = 10; output = string.Format("the int is {0}", i); versus string output; int i = 10; output = "the int is " + i; I have always ...
5
votes
2answers
233 views

Is there any language-agnostic specification for “String Natural Sorting Order”

As I painfully try to find a good natural sorting algorithm written in JavaScript I then stumble upon a bunch of different implementations, & interesting blog posts & answers on Stack ...
5
votes
1answer
234 views

String class based on graphemes?

I'm wondering why we don't have some string classes that represent a string of Unicode grapheme clusters instead of code points or characters. It seems to me that in most applications it would be ...
5
votes
4answers
728 views

Why doesn't Haskell have a 'format' function for string interpolation?

I'm trying to use Shake and I stumbled upon the following problem: there's no easy and convenient way to interpolate a string. I know about Text.Printf — it's not what I'm looking for. The ...
4
votes
3answers
467 views

What should I consider when converting from ASCII to Unicode?

For instance if I had only ASCII characters and then switched to Unicode now I have to consider special characters, and bigger strings or chars. What else along these lines should I be considering? ...
4
votes
1answer
141 views

Understanding Boyer-Moore Algorithm

Edit: I've found the original publication. It seems to me that the original does not have a l′(i). But I could be wrong because the definition of rpr(i) is so obscure to me. I'm not sure how it makes ...
3
votes
5answers
2k views

A string is immutable, so why are they not all constants?

The string type is immutable. We can use the const keyword with strings in high level language like .NET. My understanding of 'const' means constant (it remains the same, we can't change the value). ...
3
votes
5answers
4k views

How do you compress ASCII strings into smaller bytes?

I'm working with an embedded device with a unique protocol that sends messages to other devices and I'm making an application that parses the sent packets. Each packet carries 8 bytes. The protocol is ...
3
votes
1answer
135 views

How to fix legacy code that uses <string.h> unsafely?

We've got a bunch of legacy code, written in straight C (some of which is K&R!), which for many, many years has been compiled using Visual C 6.0 (circa 1998) on an XP machine. We realize this is ...
3
votes
3answers
215 views

Storing lots of large strings with frequent “appends” and few reads

In my current project, I need to store a very long ASCII string to each instance of a given object. This string will receive an 2 appends per minute and will not be retrieved so frequently. The ...
3
votes
2answers
199 views

Algorithm for finding automorphisms of a string in O(n) time

I recently stumbled upon this problem, which requires a solution in O(n) time, and I'm struggling to find a correct one. The obvious, naive solution runs in O(n²) time. Any ideas? A string S = ...
2
votes
3answers
4k views

Why does Java's String class not implement a more efficient indexOf()?

Following the below question on Stack Overflow http://stackoverflow.com/questions/5564610/fast-alernative-for-stringindexofstring-str I got to wondering why it is that java (6 at least) not use a ...
2
votes
6answers
390 views

Settle an Argument: String vs. Array?

True or False: A string is the same thing as an array. I had an interview the other day and the above question was asked. I said false, but the interviewer said it was actually true. I explained to ...
2
votes
3answers
919 views

Why do people put '\n' at the beginning of strings?

Very often I get into C code where printf format strings start with \n: printf( "\nHello" ); This in my opinion is an annoying thing that offers no advantages (rather many disadvantages!) with ...
2
votes
3answers
367 views

Why are the arguments for substring functions mismatched?

In many languages, the substring function works like this: substring(startIndex, endIndex) returns the substring from startIndex until endIndex-1 (if you view startIndex and endIndex as 0-based) / ...
2
votes
2answers
121 views

What direction should I consider the offset when searching strings in reverse?

I'm making an indexOfReverse utility function in my C++ program, and I have caught a bit of a snag. Implementing the offset and maxOffset in my indexOf was very intuitive to me.. These start from the ...
2
votes
1answer
121 views

Comparing strings against a pool of words

I am creating an app where the user enters 8 characters. After he enters the string I have to see if it is an eight letter word. If not, check if contains a seven letter word etc. I am checking ...
2
votes
1answer
29 views

performance issues when synchronizing on an interned String

I want to lock a remote file with the string "ip + filename" using java. public boolean execCmd(String ip,String filename, String command) { String file = ip + filename; String lock = ...
2
votes
1answer
497 views

Types of quotes for an HTML templating language

I'm developing a templating language, and now I'm trying to decide on what I should do with quotes. I'm thinking about having 3 different types of quotes which are all handled differently: ...
1
vote
4answers
1k views

Regex to String generation

Let's say that we have a regex and an index i. If we suppose that the set of strings that match our regex are sorted in a lexicographical order, how could we get the i element of this list? Edit : I ...
1
vote
2answers
208 views

What's the difference of an object being final and an object being immutable in java?

final String str = "do not change me"; str = "why not?"; //it will result in compile time error saying that final fields can not be re-assigned once created i.e. the reference cannot be changed ...
1
vote
2answers
415 views

Looking for a non-cryptographic hash function that returns a single character

Suppose I have a dictionary of ASCII words stored in uppercase. I also want to save those words into separate files so that the total word count of each file is approximately the same. By simply ...
1
vote
3answers
1k views

Search for a sub-string in a given array of strings

I have an array of n strings. I want to select all the elements of the array that starts with the given string. Sorry if that is not clear. I'll give an example. input = "as" array = ["abas", ...