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

0
votes
0answers
23 views

finding optimal token definitions for compression

I have a collection of strings which have a lot of common substrings, and I'm trying to find a good way to define tokens to compress them. For instance, if my strings are: s1 = "String" s2 = "Bool" ...
0
votes
1answer
42 views

Most Pythonic way to remove first match of potential leading strings?

This is a bit difficult to describe, but I'll do my best. In Python, I can use string.startswith(tuple) to test for multiple matches. But startswith only returns a boolean answer, whether or not it ...
-1
votes
1answer
75 views

Parsing a string with multiple levels of key value pairs

I need to write a part of the program which will work with a string, find in it some substrings and copy they to dictionary. Example of the string: thestring ='\ #: somethings\nchars0 ...
3
votes
2answers
164 views

Most efficient strategy for search large text areas for multiple values

I have a requirement for a service that does the following. Take a block of text and identify the server names in it (by name or ip address). So given: Lorem ipsum dolor sit amet, consectetur ...
5
votes
2answers
191 views

Is “use ”abc“.equals(myString) instead of myString.equals(”abc“) to avoid null pointer exception” already problematic in terms of business logic?

I heard numerous times that when comparing Strings in Java, to avoid null pointer exception, we should use "abc".equals(myString) instead of myString.equals("abc"), but my question is, is this idea ...
1
vote
1answer
43 views

Should arbitrary numbers be stored as strings in a database?

I'm using Google as a login system for my latest project. So, my users table has a column named googleid, which stores Google's unique user id, which is a number, with a few dozen digits. For example, ...
-2
votes
1answer
98 views

Find missing number in sequence in string [closed]

I have a string that contains numbers in sequence. There are no delimiters between numbers. I have to find missing number in that sequence. For example: 176517661768 is missing the number: 1767 ...
7
votes
2answers
312 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 ...
1
vote
4answers
672 views

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

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
124 views

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

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
239 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
98 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
350 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
1k 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
1k 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 ...
3
votes
1answer
165 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
344 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
93 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
138 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
77 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
550 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
258 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
66 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 ...
20
votes
3answers
2k 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
202 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
183 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 ...
0
votes
0answers
76 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
341 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
472 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
194 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
346 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
54 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
140 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 ...
12
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
154 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
154 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
574 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
304 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 ...
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
877 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
239 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 ...
3
votes
1answer
969 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
202 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
491 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
53 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
136 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 ...