Questions tagged [strings]

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.

Filter by
Sorted by
Tagged with
0
votes
0answers
3 views

Empty string or empty string literal? [on hold]

Is there some reason, from the programmer's point of view, to say "empty string" instead of "empty string literal"? (Yes, 1 additional word, but it is more explicit and logic. Isn't it?) a = "foo" b =...
0
votes
1answer
141 views

Should “NaN” default to SNaN or QNaN

I created a function to read floats (IEEE 754 binary 32-bit) from strings, for developers. I have everything finished and working perfectly, except i'm wondering if a user/or programmer enters a ...
1
vote
4answers
211 views

Should I always use iterators when working with strings?

Here is the known old way to iterate over the string: for (int i = 0; i < str.length(); i++) { char c = str[i]; } However recently I have also seen in multiple places the usage of ...
2
votes
3answers
3k views

Find longest word in a string: are any of these algorithms good? [closed]

I'm trying to find the longest word in a given text, but it has to be done "old school": without using split, enumerate, etc. (I'm using Python but what I'm looking for is more of a pseudocode or a ...
1
vote
1answer
124 views

How much an iterator should do

I am working on creating iterators, for strings, lists, trees, graphs, and potentially other things. First a side note. I have a string data type in my engine. The string is implemented as a bunch ...
-4
votes
1answer
91 views

What happen to string.ToCommonSenseCase()?

I'm very confused about this. In most programming languages, there are string.ToUpperCase(), string.ToLowerCase(), sometimes Capitalize() (which capitalize the first letter of the string), even ...
1
vote
2answers
116 views

Is it a good idea to use strings in a struct as values to static properties?

I'm in a discussion with a co-worker concerning the use of structs. I have a couple of structs that contain several static properties that are used throughout our website. The value of those ...
2
votes
4answers
515 views

What is a good place, in OO, to store a string that is used many places?

I have a string that is used in a few places. string portalLoginPath = $"{Request.Scheme}{Uri.SchemeDelimiter}{Request.Host}/Account/Login"; I was thinking of creating a static class with a string ...
0
votes
1answer
153 views

A collision-free hash-like function for use in hash tables and other data structures?

A short introduction to the problem: I'm working with a small database where I have a table of strings (web URLs, to be precise) as pairs: hash|string. Another table references these strings by hash ...
0
votes
1answer
65 views

Subdomain matching

I am working on a small plugin for a DNS server. I have a static list of domain (sometimes subdomains too) names: gaming.xyz.com facebook.com mail.example.com blog.example.com I want to check if a ...
2
votes
3answers
407 views

Java String substring() and StringBuilder delete() methods

I've noticed that some methods like the String's substring(int beginIndex, int endIndex) and StringBuilder's delete(int beginIndex, int endIndex), use the second parameter to signify that the ...
12
votes
4answers
823 views

struct with nonsensical default value

In my system I frequently operate with airport codes ("YYZ", "LAX", "SFO", etc.), they are always in the exact same format (3 letter, represented as uppercase). The system typically deals with 25-50 ...
1
vote
3answers
230 views

Algorithm for optimizing text compression

I am looking for text compression algorithms (natural language compression, rather than compression of arbitrary binary data). I have seen for example An Efficient Compression Code for Text ...
3
votes
1answer
241 views

How the rope data structure works when doing syntax highlighting

I am looking into the Rope Data Structure, used by some text editors like the xi editor. I get the basics of how it works, and have seen some sample implementations such as here or here. But I am ...
2
votes
1answer
239 views

Data Structure for “Intuitive” Text Matching

I've noticed that text editors and such have a more-than-prefix/suffix-based pattern matching algorithm going on behind the scenes. And StackOverflow's tag matching algorithm does more than just ...
2
votes
4answers
397 views

What is the optimal way to perform 5000 unique string replace functions in terms of performance?

Restructuring some code, and the way I built it up over time has portions that look something like this: s.replace("ABW"," Aruba "); s.replace("AFG"," Afghanistan "); s.replace("AGO"," Angola "); s....
1
vote
1answer
2k views

Efficient multiple substrings search

I have many substrings(2-5 words each) which I would like to search in some text of about 40-50 words length. What is the most efficient way to flag matching substrings. Currently I am simply using: ...
0
votes
2answers
2k views

changing the value of String object in java

I have to set the value of a string object "result" depending on the results of different methods and different if/else conditions. In the end, there would be one (last value set) in the string that i ...
-2
votes
1answer
75 views

Is it a good idea to have a string.xml to house all strings in a web application

In Android Framework there is a string.xml file that houses all the strings for the application. This allows for easier re-use and possible internationalization. My question is, is there any ...
-3
votes
1answer
197 views

Creating String with equal operator vs new operator? [closed]

I have seen most of times developer declares the string in below fashion Approach 1:- public void method1(){ String str1 ="Test"; } Approach 2:- Per my understanding better approach will be ...
16
votes
3answers
5k views

When should I use string_view in an interface?

I'm using an internal library that was designed to mimic a proposed C++ library, and sometime in the past few years I see its interface changed from using std::string to string_view. So I dutifully ...
3
votes
1answer
597 views

Why doesn't Swift allow Int String subscripting and integer ranges directly?

If I have a string: let str = "Hello world" It seems quite reasonable to be able to extract a character: let thirdChar = str[3] However, that's not legal. Instead, I have to use the extremely ...
1
vote
0answers
117 views

speed up search in string array [closed]

Suppose we have sorted array of strings e.g. std::vector<std::string> or some other elements with string as key - for example std::vector<std::pair<std::string,data_type>. Normally to ...
3
votes
1answer
548 views

Which is a more efficient approach to decoding escape sequences in text?

I'm working on parsers that not only process delimited content, but also escape sequences within certain portions of that content. I'm contemplating the efficiency of several approaches to ...
0
votes
1answer
53 views

Simple algorithm for computing an orderable value from a string

I would like to compute a numeric value for strings containing only /[a-z0-9]/i (ignore case). Later, I want to use this value for sorting rows. For this post, I am ignoring number also. My thinking ...
11
votes
8answers
12k views

Are C strings always null terminated, or does it depend on the platform?

Right now I am working with embedded systems and figuring out ways to implement strings on a microprocessor with no operating system. So far what I am doing is just using the idea of having NULL ...
6
votes
2answers
2k views

Detecting plagiarism – what algorithm?

I'm currently writing a program to read a body of text and compare it to search-engine results (from searching for substrings of the given text), with the goal of detecting plagiarism in, for example, ...
0
votes
3answers
344 views

algorithm for perfect substring temporarily replacement

I have an interesting question about string and delimiters. There is a random string str. There are some symbols (OR SEQUENCES OF SYMBOLS) that are predefined and should be temporarily replaced ...
1
vote
2answers
166 views

Is there a good single byte delimeter for use with utf-8 strings that isn't a null terminator?

I'm looking for a quick way to split strings containing individual JSON payloads. Currently, I'm using newlines and searching for the newline ASCII character, but I figure if I start using utf-8 this ...
-6
votes
2answers
253 views

Which piece of code is more efficient with respect to Time and Memory cost? [closed]

Code 1: private static int myCompare(String a, String b) { /* my version of the compareTo method from the String Java class */ int len1 = a.length(); int len2 = b.length(); if (...
11
votes
2answers
6k views

Why PHP treats “0” as FALSE in boolean contexts?

"0", as a string containing one character, is not something empty intuitively. Why does PHP treat it as FALSE when converted to a boolean, unlike other programming languages?
19
votes
7answers
1k views

Is it bad practice to store certain values as strings?

That's a very vague title but I couldn't think of a better way to word it. But, just as an example, think about the direction that a character in a game is moving in. It just feels kind of wrong to be ...
5
votes
3answers
293 views

Is it good practice to ever cast a boolean to an integer for arithmetic?

If I have a function where I am operating on a specific offset within a string, and the exact location of this offset depends on a previous test within the function, is it "bad practice" or "ugly" to ...
10
votes
5answers
710 views

Is placing text markers inside of strings bad style? Is there an alternative?

I work with massive strings which need a lot of manipulation. For example, I might generate a string like this: Part 1 Boat Section A Programming Part 2 Partitioning boats for ...
2
votes
4answers
180 views

What coding practices are most useful dealing with trailing whitespace in data fields in binary files?

We have an application that consists binary files (containing a mix of text and numeric information) and programs written in various languages that create, modify and read these binary files. Because ...
10
votes
5answers
2k views

Optimizing redundant string allocations in C++

I have a fairly complex C++ component whose performance has become a problem. Profiling shows that that most of the execution time is simply spent allocating memory for std::strings. I know that ...
0
votes
2answers
143 views

Strip spaces before saving to DB or while outputting?

Imagine scenario: need to strip out spaces from a string to be used lets say in url. Now would it be smart to do this once before saving in DB, and than use raw db results when outputting. Or would ...
-2
votes
1answer
608 views

What string will match the regular expression (^$)|(^.*\\{count\\}.*$)\n?

I'm trying to pass a parameter to create a thumbnail in AWS Elastic transcoder, which shouldn't be that difficult except I know nothing about regular expressions. My log is giving me the following ...
7
votes
2answers
10k views

What's the complexity of Java's string split function?

My string is of type"abacsdsdvvsg" or"a a a a a a a" And I use String[] stringArray = s.split(""); or String[] stringArray = s.split(" "); I'm wondering what would be the complexity(in O(string length)...
13
votes
1answer
1k views

Why are the punctuation characters in the ASCII table all over the place?

In the ASCII table, punctuation characters appear between the non-printing characters and before the numbers (!"#$%&')*+,-./), between the numbers and the uppercase letters (:;<=>?@), ...
7
votes
4answers
1k views

How can I count frequency of strings?

I have 3 billion strings. I want to make a frequency map so I can discard strings that occur fewer than 100 times or more than 100,000 times. What kind of data structure(s) should I use? I'm ...
1
vote
4answers
1k views

immutable string in array, reference type vs value type

Trying to understand strings better in C# Are these assertions correct? string is immutable string is reference type but behaves like value type For these code samples... string x = "one" (...
0
votes
2answers
129 views

Variable can't hold str() method information with “pure” word in brackets… why?

I've recently bumped into string methods and mainly str() method caught my interest because, it makes string out of every type of data? integers, booleans and so on. And if you want, they can be ...
0
votes
1answer
435 views

Problem while printing characters Difference between System.out.println('A') and System.out.println(+'A') [closed]

Why is it that : System.out.println(+'A') //gives output as 65 System.out.println('A') //gives output as A Also System.out.println(8+4+'A'+"PRIME"+4+4+'A'); gives output as 77PRIME44A ...
4
votes
6answers
38k views

How to create multiline strings for sql queries that are readable, maintainable and fast?

I have some SQL commands that I am trying to figure out the best way to have them in code so that: 1. They are very readable 2. They would be easy to update 3. They won't be performance overhead due ...
1
vote
2answers
206 views

How can I include common strings (regexes) in several projects written in different languages?

I have a simple Go library (~300 lines, mostly type declarations and nice methods and compatibility methods for gomobile etc., also pretty-printing scripts). The heart of the whole project are two ...
6
votes
2answers
2k views

Memory usage of JavaScript string type with identical values

JavaScript string type is immutable, but does it mean identical strings will share memory? Say two strings are created in complete different places, will a modern JavaScript engine be smart enough to ...
6
votes
3answers
3k views

Compiling for string and wstring

I'm creating a library. I want to use it in multiple projects which may use multi-byte or unicode (std::string or std::wstring). I've adopted the old MS method of conditional compiling: namespace ...
0
votes
1answer
1k views

URL endpoint concatenating

When writing API clients, what is considered the proper way of concatenating a URL together with multiple endpoints? For example with the Blizzard API: WowEndpoints := [...]string{"achievements", "...
7
votes
2answers
242 views

Finding and counting equal substrings in a set of strings

I'm thinking about a way of finding similar parts in Strings. I have a set of strings of varying length i.e: The quick brown fox jumps fox force five the bunny is much quicker than the fox is First, ...