A "string" is a sequence of characters typically representing a unit of human-readable text. Questions on this topic deal with processing strings in programs, and how various languages and environments define and manipulate strings.

learn more… | top users | synonyms

4
votes
2answers
80 views

Compile-time checking for NULL initialized std::string

This is sort of the complementary question to How to best protect from 0 passed to std::string parameters?. Basically, I'm trying to figure out whether there is a way to have the compiler warn me if a ...
4
votes
5answers
444 views

Why do so many languages restrict string literals to a single source line? [on hold]

In, for example, the Bash scripting language, the following creates a string called $VAR which begins at the first " quote and continues until the next unescaped " quote. $VAR=" hello world! ...
0
votes
1answer
91 views

Algorithm to get all possible forms of a word with varying suffixes

I'm writing an application in javascript where given a word, I need to get all the possible versions of the word with the suffix being the difference between each form. For example: "sponsor" should ...
-1
votes
1answer
225 views

In which cases and examples String in Java is not immutable? [duplicate]

If Strings are immutable in Java, why is the output of this code 2GB, instead of 1GB? class Laptop { String memory = "1GB"; } class Workshop { public static void main(String args[]) { ...
-1
votes
1answer
78 views

Speeding up appending text in C# [duplicate]

I'm trying to append text to a large amount of strings (in the thousands), and also do some other string manipulations. However, I have about 60 lines of if/else and string appending and it takes ...
0
votes
2answers
304 views

How to scramble a word, keeping first and last characters the same?

I have a task, which is to scramble a single word, whose size is greater than 3 letters. The scrambled word must not be equal to the original, and the first and last letters of the word must remain ...
7
votes
6answers
899 views

Is “string literal” always the same as “hard-coded string”? [closed]

I am learning programming and often see the term "string literal" being used in various places. From the looks of it, it seems to be a synonym for "hard-coded string", but on another hand the term ...
4
votes
4answers
892 views

Why is %s better than + for concatenation?

I understand that we should use %s to concatenate a string rather than + in Python. I could do any of: hello = "hello" world = "world" print hello + " " + world print "%s %s" % (hello, world) print ...
2
votes
1answer
92 views

Burrows-Wheeler transform backward search: how to find suffix index?

BWT backward search algorithm is pretty straightforward if we only need the multiplicity of a pattern. However I also need to find the suffix indices (i.e. positions in the reference string where a ...
2
votes
3answers
322 views

Why do most language's definition of substring allow substring(“abc”, 3) => “”

I've seen most languages have it be the case for their substring method that using the length of a given string in the method as the start index will give you an empty string. It is most definitely ...
-2
votes
2answers
74 views

Find index of string in an array of strings where overlap could occur

I am having some trouble writing a variant of sub-string search. Essentially the goal is to write a method that can perform sub-string search except that the source data is in an array of Strings ...
0
votes
2answers
102 views

Incrementing Strings in PHP (and Perl)

PHP allows you to increment strings. Why? Let's jump ahead a bit. Take the following code: $string = '9ZzZ'; echo ++$string; // 10AaA From a purist point of view this may seem like nonsense, ...
1
vote
0answers
73 views

Algorithm for evaluating line breaks efficiently [closed]

Consider following problem : Given: String input with the length n Font(-metrics) - potentially slow in usage Bounds of an abstract Textview which shall contain the text in a specific manner: e.g ...
-2
votes
4answers
321 views

In C# Is using private constant strings better than using strings directly in the code? [closed]

Consider the following two cases: case 1: class A { private const string MyConst="Hello"; internal void CallMe() { System.Console.WriteLine(MyConst); } } Case2: class A { ...
0
votes
1answer
222 views

What operating systems will “\n” create a new line in? (Java) [closed]

(Java Version 8 Update 60) Hello. I am currently writing a program for my first Java assignment in college. My question is, in what operating systems will System.out.println("Hello,\n World"); ...
3
votes
1answer
64 views

CharSequence to represent a named object

I always followed the opinion to not abuse interfaces in case of decomposition. Usually I only implement them if I am absolutely sure to have a "is-a"-relation and avoid implementing them if there is ...
19
votes
3answers
1k views

Why are C string literals read-only?

What advantage(s) of string literals being read-only justify(-ies/-ied) the: Yet another way to shoot yourself in the foot char *foo = "bar"; foo[0] = 'd'; /* SEGFAULT */ Inability to elegantly ...
1
vote
2answers
225 views

Why are Strings in StringPool considered insecure?

Passwords are recommended to be stored in char[] instead of String, as Strings are stored in StringPool. Read more here As per this question Strings in StringPool are not available directly. To ...
4
votes
2answers
185 views

Are string characters assigned a numerical value in context of how they are assigned in a programming language?

For context I am fairly new to programming after returning back to it after programming a number of years ago... I was reading Bjarne's intro programming with C++ and was wondering if alphabetical ...
4
votes
2answers
150 views

why regex, when using global search and {0,} quantifier, match the end of the string?

I have asked a question here about js, regex, quantifiers and global search. I've understood finally how this works, but, let's take a concrete example and then I`ll write my question. Based on the ...
1
vote
0answers
61 views

clustering of strings with variable-length prefixes

I've got bunch of strings with variable-length prefixes (or postfixes - I can always revert them) as follows: 0155555555 523455555555 755555555 ... 87129999999999999 119999999999999 09119999999999999 ...
0
votes
2answers
282 views

Why can't I use an operator like plus sign to concatenate strings? [closed]

Why in Objective-C we should be typing explicit references to methods like stringByAppendingString to concatenate strings, when in some other languages we can use operators for that? For example, ...
0
votes
2answers
389 views

Why should I use lookup tables at all?

This question confirmed, what I was already aware of -- instead of directly storing strings in table, I should rather use integers or enums and join them with lookup table, to get, as a result, ...
2
votes
3answers
184 views

At which point using string-based enums can become a real problem?

This is a direct follower to this question. An answer given to that questions says (my understanding), that nowadays using string-based enums instead of integers isn't a much problem, because hosting ...
1
vote
4answers
345 views

How can I avoid the use of strings?

I'm implementing a program where the user can 'create a musical scale' from a variety of notes (identified by their names), and the program will generate music from this scale. I want to implement a ...
1
vote
0answers
50 views

String Rearrangement Algorithm in Visual Basic

Beginning programmer here (mostly engineer). I'm making trapezoids in layers. We begin with the small length layer, and end with the longest length layer. I want my user to input in a desired ...
5
votes
1answer
107 views

Use StringLike instead of String in Scala?

Scala has the StringLike trait. Let's say I want to create a case class Name and internally it should save the name with some characters. Should I use case class Name(name: StringLike) or case class ...
39
votes
6answers
7k views

Hardcoding strings that will never change

So, in my efforts to write a program to conjugate verbs (algorithmically, not through a dataset) for French, I've come across a slight problem. The algorithm to conjugate the verbs is actually fairly ...
11
votes
2answers
1k views

Why store flags/enums in a database as strings instead of integers?

I've been browsing SQL dumps of some famous CMSes, including Drupal 7, Wordpress (some quite very old version), and some custom application based on Python. All of these dumps contained data with ...
0
votes
2answers
153 views

Detecting and Dealing with obscene language in user input

I've seen some pretty darned restrictive 'chat-systems' in kids games, that make it nigh-on-impossible to get much of a message across whilst typing. So, I looked at some ideas, and there where two ...
0
votes
0answers
127 views

Compare names and the use of Levenshtein's algorithm

I need to cross names from two lists. What is the best away to compare the names? As you may expect, in one list we can have the complete name, on the other just the first and last. Besides that, ...
0
votes
5answers
548 views

Is String processing more complex than number processing in programming languages?

I feel that string processing is always more complex than Numbers or mathematical processing. Are our programming languages are designed this way that mathematical operations are pretty much straight ...
0
votes
1answer
261 views

Making a database and related operators using files and JSON in java [closed]

I'm trying to write a program that reads operations from a file. these operators look like below : CREATE TABLE student(id:integer, gpa:decimal, name:string, family:string,isMale:Boolean) INSERT ...
-2
votes
1answer
247 views

Does datetime.fromtimestamp() return a datetime object or a string?

Basically what the title says. This is a more theoretical question than anything, I don't have a specific use for it. I've looked up the documentation and I can't find a definite answer.
3
votes
2answers
6k views

Which way is more efficient for getting the space count?

I have just started reading Cracking the Coding Interview. One of the problems (specifically 1.4) after solving and then looking at the answer made me question the way it is done and decided to post ...
2
votes
4answers
1k views

How to automatically connect letters into words? [closed]

I would like to connect letters into meaningful words? E.g. input: T E ST IN G WE B A P P LIC AT IO N S output: TESTING WEB APPLICATIONS what kind of task is this? A task in NLP, or just some ...
4
votes
2answers
722 views

Number of strings containing a specific substring

I've seen numerous questions (and answers) concerning the number of binary strings (e.g "10010" containing some binary substring (e.g "00"). I'd like to know if there is a way to generalize this: ...
9
votes
3answers
236 views

number of strings, when each character must occur even times

I've been bashing my skull at this problem for some time now, and its really starting to frustrate me. The problem is: I have a set of characters, A, B, C, and D. I have to tell in how many ways a ...
2
votes
1answer
368 views

Functions returning strings, good style?

In my C programs I often need a way to make a string representation of my ADTs. Even if I don't need to print the string to screen in any way, it is neat to have such method for debugging. So this ...
0
votes
3answers
194 views

Should I be extracting strings from source in core java the way android does?

I just started doing android development stuff after getting pretty comfortable with Java. Android apps tend to do this weird thing where they have all strings for their program held in an XML file ...
0
votes
6answers
433 views

Why 'String' objects are immutable with an explicit constructor in java? [duplicate]

It make sense to make class String objects immutable with following declarations, because they share the same storage in common pool. String str1 = "abc"; String str2 = "abc"; But, am not sure, if ...
0
votes
1answer
38 views

String splits to create arrays

Creating an array of strings for configuration or verification purposes can get long and ugly in code. For example: arrayOfStrings = ['one','two','three','four'] Often to reduce the characters and ...
2
votes
1answer
49 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 = ...
1
vote
2answers
135 views

Return equal occurrence of char in a list of strings

I have an array of strings ["abb", "bbxxaa"]. I would like to print all characters that occur equal times in each index so in above case I would print bb because they occur twice in both indexes and ...
4
votes
1answer
204 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 ...
5
votes
2answers
404 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 ...
4
votes
1answer
168 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 ...
-2
votes
2answers
7k views

How does std::string in c++ allocate memory? [closed]

I've noticed that the string library doesn't require one to allocate space before writing the input/output. How does the string library allocate that memory dynamically, i know of the 'new' keyword in ...
1
vote
2answers
213 views

Is there a stricter strtoull() in any ubiquitous C library?

I want a function that will interpret a string as a strictly unsigned integer, failing when the string overflows, represents a negative number, or does not represent a number. strtoull() does set ...
0
votes
1answer
2k views

VB.NET - Serial Key Generating (Encryption, Hashing, Encoding?) Algorithm

I am trying to create a basic licensing system where I take a unique ID from the client computer, and I get this Hexadecimal string (hyphens removed e.g. "84-18-CE-...."): ...