Stack Exchange Network

Stack Exchange network consists of 175 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. It is commonly used to represent text or a sequence of bytes. Use this tag along with the appropriate programming language being used.

10
votes
1answer
5k views

Converting a range of integers from a string to an IEnumerable

Goal Convert the following into an IEnumerable of integers accounting for the x-y ranges: ...
2
votes
4answers
5k views

is it a good strlcat() implementation?

I'd like to know if i respect strlcat(3) behiour with my implementation, cause i'm not really sure to understand strlcat particular behaviour ...
4
votes
1answer
4k views

Convert .NET DateTime to a string using ordinals

With a DateTime object, it's easy to get, for example, 11 October 2011 by using: d.ToString("d MMMM yyyy"); However, there ...
6
votes
5answers
3k views

Better way to write a string slicer

Here is some code to insert a new line escape sequence after a certain number of characters (for fixed width displays) ...
8
votes
2answers
151 views

String substitutions in ruby and coding style

I wrote a short ruby script to generate various screenshots, and event though I am not completely new to ruby I rarely use it. Full script (41 LOC): https://gist.github.com/1229115 The string ...
6
votes
4answers
465 views

Simplifying ToString() implementation

Any ideas? ...
1
vote
1answer
5k views

Serialization/Unserialization of a list of strings - C++

Are there any issues with below implementation? Input: from STDIN, a list of strings Output: serialize to a file called "out.txt" and then unserialize into a list of strings, and output to STDOUT ...
3
votes
2answers
14k views

Splitting a string in an SQL query

BudgetCode is in the format 'xxxx-yyyyy-zzzzz'. This splits it correctly but I think that there has to be a more efficient way. ...
1
vote
1answer
185 views

Encode strings by subtracting one from each character code

I currently have this encoding function which simply subtracts one from each character code: ...
5
votes
3answers
4k views

Split post string into hash

...
2
votes
2answers
3k views

Function to validate a file name

This function checks if a file name is valid or not. I think it's not good enough for integration (not optimized, maybe I forgot about some checks), so need your comments. ...
5
votes
1answer
559 views

Processing XML configuration which stores regular expressions and format strings for a documentation tool

I'm investigating some feature for the ScalaDoc tool, which would allow library writers to link to documentation created by third party tools like JavaDoc. My idea is to have some (XML) configuration ...
5
votes
5answers
7k views

Determining whether a string ends with one of a few given options

I wrote the following function to determine whether a string ends with one of a few given options. I'm sure it can be written more elegantly, probably avoiding the loop. ...
4
votes
3answers
5k views

String manipulation complexity

I've been reading Cracking the Coding Interview and at the very beginning I got to the strange statement that the next complexity will be \$O(n^2)\$. ...
3
votes
5answers
4k views

Delete each character in one string that matches any character in another

I am trying to solve an exercise in which I am given the following function: ...
6
votes
2answers
272 views

Determining which command line arguments are numeric

I am working on using STL and in general safe C++ practices. Instead of posting large samples of code I am working with a small sample to catch problems before I move onto larger ones. How do you ...
28
votes
1answer
63k views

Pack and unpack bytes to strings

I need to write a function that "packs" an array of bytes (integers between 0 and 255) into a string. I also need to be able to perform the reverse operation, to get my byte array from the string that ...
3
votes
2answers
840 views

Remove repeated words from a 2D character array

This code removes repeated words from a word array (2D char array). I want to optimize this as much possible for speed. ...
0
votes
2answers
2k views

Command line tool for extracting, searching, and converting

I just completed my first real application (command line app). It's simple, but I had no prior knowledge of Python. Everything was hit and miss, with many Python books and help from those in this ...
3
votes
5answers
7k views

Replace sequence of strings in binary file

I have searched for method to find and replace strings sequence in binary files without any luck. The main requirement was that method should not load all file in memory but rather use chunks. I am ...
13
votes
5answers
16k views

Remove useless whitespace from styled string

I have a big string resource (basically the "about" text of the application) which contains styles (such as <b>, <a> ...
2
votes
3answers
158 views

XML-tag function

I'm an experienced programmer, but just a beginner in Python, and would like some input on a small function that's working but which I'm not very happy with. It's used to produce XML tags (strings). ...
7
votes
3answers
370 views

Determining if one string occurs at the end of another

This is exercise 5-4 from K&R. I spent hours tweaking it but now it seems to work. I'm new to pointers and I'd welcome any comments about how to do it better. ...
12
votes
4answers
50k views

Simplify splitting a String into alpha and numeric parts

Requirement: Parse a String into chunks of numeric characters and alpha characters. Alpha characters should be separated from the numeric, other characters should be ignored. Example Data: Input ...
2
votes
2answers
276 views

Iterate comparison - How can I write this better?

I would like to write the following piece of code cleaner and more efficient, any comments will be greatly appreciated: ...
10
votes
4answers
2k views

Change upper or lowercase vowels to [0,1,2,3,4] respectively and leave the rest the same

The objective was the following to be solved in Python: Given a string, def a function that returns another string with the vowels (upper or lowercase) replaced by 0,1,2,3,4 respectively. ...
14
votes
10answers
12k views

Looping through a collection

In the situation where I am looping through a collection looking for an item, is it better practice to break before I return or ...
7
votes
4answers
657 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 ...
147
votes
14answers
45k 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
26k 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 ...
17
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
934 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
323 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: ...
12
votes
2answers
11k 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: ...
36
votes
5answers
3k views

Sorting strings by length - functional Python

I'm trying to port this little F# snippet while staying pythonic: ...
5
votes
1answer
182 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
743 views

Capitalize words in sentence

...
224
votes
14answers
36k 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
643 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
337 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. ...
34
votes
9answers
80k 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 ...
7
votes
4answers
294 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 ...
20
votes
7answers
23k views

Function for removing forbidden characters

...
11
votes
2answers
366 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? ...
21
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? ...