Questions tagged [strings]

A string is a sequence of characters. It is commonly used to represent text or a sequence of bytes. Use this tag along with the appropriate programming language being used.

Filter by
Sorted by
Tagged with
7
votes
4answers
660 views

Managing part types and counts

Both functions look fairly similar to each other, but they are different in the type of string. I have 6 functions like this and all differ only in the "string cmd". Any ideas on how I can put it all ...
159
votes
14answers
58k views

Remove Last Comma

I want to join strings together, but when doing this it often happens that there is a comma too many, and therefore I need to remove that comma. In this code, I use the ...
11
votes
10answers
27k views

Optimizing Java Anagram checker (compare 2 strings)

An anagram is like a mix-up of the letters in a string: pots is an anagram of stop Wilma is an anagram of ilWma I am going through the book Cracking the Coding Interview and in the basic ...
18
votes
11answers
1k views

Reversing a string

I had this as an interview question, and the interviewer pointed this out. Here's what I wrote: ...
2
votes
6answers
1k views

Change HashSet to a set of strings found in a file

This function changes a HashSet in the root of the class called 'commands' to a set of strings found in a file at "plugins/UC/Commands.txt" (it's what was requested by the people using the plugin). ...
2
votes
1answer
325 views

Abstract the (duplicate?) behavior between “sort” and “replace”

I have written these two functions that have a similar process. The first is meant to "split" a string on a given character and the second is meant to "replace-all" instances of a character in a ...
11
votes
4answers
2k views

Filtering a recursive directory listing, discarding subfolders

I needed a function that would take a list of folders and removed all sub folders, so that only the top level folders stayed in the list. For example, given the list: ...
4
votes
2answers
3k views

Print an integer and its digits reversed

This Common Lisp program is an exercise to print an integer and its digits reversed to the screen: ...
14
votes
2answers
14k views

C++ string_cast<> template function

In C++, to simplify string conversion between std::string and std::wstring, I created the following utility template functions: ...
11
votes
4answers
1k views

Different character outputs using loops and strings

I've just given this as a response to an absolute beginner on SO, and I'm wondering how terrible it is. Output for an odd number of lines: ...
37
votes
5answers
4k views

Sorting strings by length - functional Python

I'm trying to port this little F# snippet while staying pythonic: ...
5
votes
1answer
184 views

Substitution of different occurrences of a string with changing patterns

I need to parse an invalid JSON string in which I find many repetitions of the same key, like the following snippet: ...
8
votes
3answers
987 views

Capitalize words in sentence

...
240
votes
14answers
42k views

Calculating entropy of a string

We're calculating entropy of a string a few places in Stack Overflow as a signifier of low quality. I whipped up this simple method which counts unique characters in a string, but it is quite ...
11
votes
1answer
657 views

String interpolation library

I was bored over the last couple of days and wrote up a string interpolation library for JavaScript. I'm very pleased with its functionality, it passes it 79 tests cross browser and the comments and ...
12
votes
2answers
345 views

Traversing a multidimensional structure and applying strip() to all strings

I'm trying to apply string.strip() to all the leafs that are strings in a multidimensional collection, but my Python is a bit rusty (to say the least). The ...
7
votes
3answers
2k views

Partitioning strings into substrings of fixed length

I've got a Clojure function here that's meant to parse a string of form: "DDXXXYYY" where DD is meant to be discarded, and XXX and YYY are string representations of integers. ...
40
votes
9answers
102k views

Converting between std::wstring and std::string

While researching ways to convert back and forth between std::wstring and std::string, I found this conversation on the MSDN ...
8
votes
4answers
298 views

Struct to web style string

I've had to make several functions to turn some structures into strings. I am a still green when it comes C so I am unsure if I am doing this a very awkward way. The system I am coding for does not ...
23
votes
7answers
26k views

Function for removing forbidden characters

...
12
votes
2answers
372 views

Is this a sufficient way to prevent script injections and other bad stuff in strings

Would this function be sufficient enough to remove all malicious code and foreign characters from a string? ...
24
votes
5answers
2k views

Generating CSV strings for various 3rd party utilities

I'm generating CSV strings for various 3rd party utilities and this section of code gets repeated in many classes. Is there a better way to generate this string? ...

1
50 51 52 53
54