Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

2
votes
4answers
491 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
127 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
50 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
217 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
595 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 ...
2
votes
3answers
204 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
157 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
126 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
372 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
1k 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
970 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 ...
-4
votes
1answer
195 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 ...
15
votes
3answers
3k 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
230 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
112 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
407 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
0answers
56 views

Performance comparison between filtering through an array holding custom class vs concatenated string

I have an array hold custom class objects. I don't ever need to sort. I only use it for filtering for one or multiple objects. As this array grows, the performance is starting to take a hit. I'm ...
0
votes
1answer
49 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
9k 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
1k 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
155 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
163 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 ...
-5
votes
2answers
222 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 (...
10
votes
2answers
5k 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?
18
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
288 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
703 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 ...
3
votes
4answers
170 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 ...
11
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
133 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 ...
0
votes
0answers
122 views

What is the fastest way of using conditional in Javascript when comparing multiple strings?

I have a piece of code that looks something like this var abc = function(pathin, pathout) { if(pathout === "bcd/fgh" && pathin === "egh/abcd/gh") {....} else ...
-2
votes
1answer
509 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
8k 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
968 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
121 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
266 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 ...
2
votes
6answers
28k 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
173 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 ...
5
votes
2answers
1k 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 ...
7
votes
3answers
2k 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
873 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
236 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, ...
1
vote
2answers
354 views

Do any languages other than Haskell implement strings as linked lists of characters?

Haskell’s String type is an alias for [Char] (i.e. a linked list of Chars). Does any other language use an implementation of strings like this?
5
votes
2answers
181 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
1k 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
1k 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 "substr0"\...
3
votes
2answers
865 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 ...