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.

learn more… | top users | synonyms (1)

3
votes
1answer
23 views

Function that shortens a String based on a term/abbreviation mapping with special cases

This is a update of this question since the requirements for this task changed. I have a function that takes a description as a String and returns a shortened ...
2
votes
0answers
21 views

Ruby-like squish in Haskell

squish is an onomatopoeic string function provided by Ruby on Rails that works on strings. Given a string, squish condenses all ...
3
votes
4answers
68 views

Efficiently concatenate substrings of long list of strings

I am having performance problems with the following python function: ...
19
votes
4answers
3k views

“ONCE”, “UPON”, “A”, “TIME”

I'm working on a small program to perform various tasks on text content, primarily at the word level. I wrote these methods as ways to help prepare the raw text file into something more malleable, ...
8
votes
0answers
33 views

POSIX shell compatible and POSIX conforming dirname implementation

The discussion in the comments of this answer made me wonder how hard it would be to write a built-in only version of dirname. This is what I ended up with but I'm ...
-5
votes
0answers
25 views

Ten Green Bottles please give me a hand i cant work it out [on hold]

This open a file given as filename for reading returns the String containing the contents of the file ...
6
votes
2answers
91 views

Reading awkward text fields

I have written nested while loops to read in some of the columns in a text file that looks like this: ...
7
votes
3answers
137 views

Finding the shortest excerpt that contains all search terms

Write a function called answer(document, searchTerms) which returns the shortest snippet of the document, containing all of the given search terms. The ...
6
votes
4answers
284 views

Getting a scrabble score from a word

My program is complete and runs, and gives me the output I expect. For example, if I enter the string "HELLO" I should get 8. ...
6
votes
1answer
92 views

Random String Generation - Base36 and optimization

This is some fairly heavily optimized C#. Aside from reading like C++ code due to all of the pointers, does this pass sanity checks, and is there any way to improve it, while keeping its speed (or ...
6
votes
4answers
67 views

Join strings with different delimiters and some possibly empty strings

I want to construct a string from several substrings, each one of those with a different delimiter. If the string is present, the delimiter and the string should be added, if not, none of them should ...
-3
votes
0answers
38 views

How can I shorten this string? [closed]

I have this which is used to enable GC logging: ...
1
vote
0answers
13 views

Join strings with different delimiters from possibly empty strings [duplicate]

I want to construct a string from several substrings, each one of those with a different delimiter. If the string is present, the delimiter and the string should be added, if not, none of them should ...
6
votes
1answer
61 views

Cleaning up HTML created by users

I have a system that accepts free text from users. This can either be plain text or a heavily limited subset of HTML. I've written the below with Html Agility Pack and Microsoft's AntiXss library. I ...
4
votes
2answers
46 views

Prompt user for input then create an acronym from it

My program is complete and working, but I would like second opinions on it. The program prompts the user to enter something like a phrase or some words. Then it will create an acronym of what was ...
5
votes
1answer
76 views

C implementation of a string

As C does not have a native string type, I decided to try making a similar type. It's not perfect by any means, so I was coming here to see what I could do to ...
5
votes
3answers
211 views

String to Array formatting

I'm tying to convert from this formatted string: $filtersStr = "id:1||name:alex"; to: ['id' => 1,'name' => 'alex'] ...
3
votes
1answer
51 views

Twisting words! (boustrophedon formatting)

I decided to implement properly the Code Golf challenge about twisting strings. I report the assignement verbatim for convenience: Twisting Words! Given a string and a positive integer. You ...
4
votes
2answers
81 views

Palin Pairs (Pallindrome Counting) Code

In an array of strings 'a' having 'n' strings i have to select the Palin Pairs from the given strings .for ex for input 3 bba abb abb Output=2 I am getting correct output but want to reduce time ...
7
votes
1answer
62 views

Print array of sentences vertically

Suppose I have an array of sentences: [ "How To Format", "put returns between paragraphs", "for linebreak add 2 spaces at end" ] I want to print it like this: ...
2
votes
1answer
68 views

Function to compare phone numbers

I got rejected in tech screen yesterday. I was asked to write a JavaScript function and send it over email. The question was(I have added the full question below). I have also added hiring manager's ...
6
votes
3answers
340 views

Finding the postion of a substring in a string

I am given two strings and return the position if in the larger string the smaller string is found. If not I am returning -1 for position. Any suggestions for improving my code. ...
6
votes
1answer
56 views

printf-style string formatter

As part of a larger project I'm working on, I've made a function that aims to replicate, as best as I can, the placeholder part of the console.log() function usable ...
7
votes
3answers
370 views

n number of x on the y

Everyone knows "99 bottles of beer on the wall". Mat's Mug made a comment about mugs on the wall in The 2nd Monitor and I realized I never wrote a "beer on the wall" program. But that seemed way too ...
2
votes
1answer
24 views

Getting the character index of recurring substring

I created this function that allows you to declare a string, then multiple instances of a substring. This uses a hash map to keep track of strings that have already ...
4
votes
1answer
38 views

A rename utility in Scala

I made a commandline tool for renaming files, similar to the rename command in Ubuntu. Here is the code: ...
3
votes
4answers
296 views

Get string truncated to max length

This is an extension method to get a string that is truncated to a maximum length. Any comments? ...
0
votes
1answer
12 views

Java Loops and UIs

I've always found coding UIs in Java very inefficient, and hopefully this is because of my misunderstanding. Here's a great example. I have a UI class which is returning the String "Hours", which is ...
5
votes
2answers
112 views

Function that shortens a String based on a term/abbreviation mapping

I have a function that takes a description as a String and returns a shortened version of the description. The shortening is done by checking if a word matches the ...
3
votes
2answers
36 views

Extracting and normalizing URLs in an HTML document

I have written code to get all urls on a webpage & put them in a set, and would like tips on simple changes I can make to increase its performance. ...
5
votes
5answers
380 views

Shorthand expansion exercise from K & R C (ex 3-3)

I have written a function to take some shorthand input and expand it into the full form, for example a-z0-9 becomes abcd...789. I added protection from buffer overflow exploits (knocks on wood), and ...
25
votes
4answers
2k views

Determining if two words are anagrams

I was given a this problem at a technical interview and failed miserably in the time given. Afterwards, I sat down and worked out what I think is a good solution. The task was actually to build an ...
6
votes
3answers
228 views

Get initials from full name

Going through a book, I encountered the following assignment: Write an application that asks for the user’s first, middle, and last names and replies with the user’s initials. Are there any ...
1
vote
2answers
54 views

Compensating for typos in strings by removing spaces and making uppercase for comparison

I'm working with a database that has typos in the values. To compensate for them I've made a function called standardizer() which removes spaces and converts all ...
5
votes
3answers
627 views

Function that adds two integer strings

I wrote this method that adds two integers in the form of strings together. This way I can add large integers without overflowing. How efficient is the code that I wrote? I am by no means a great ...
1
vote
2answers
55 views

Library class Project

I am creating a class project which involves two classes: Library and Book. I would like a general review on the code. ...
3
votes
1answer
67 views

Pass the password back

This code simply receives a very basic 'password' (numbers, letters, nothing fancy). After you press enter, it will display it back. The only special key I'm handling is backspace (code ...
1
vote
1answer
41 views

Generate all possible permutations from a string with character repetitions

I want to know if my code is good, with reasonable efficiency, and if it is possible to improve my code and how. What would you suggest? ...
0
votes
5answers
118 views

std::string implementation

Following is my attempt for a simple implementation for the std string class. Please review my changes and share your feedback. string.h ...
7
votes
5answers
358 views

CodeEval Challenge: Remove specified characters from a string

Question Write a program which removes specific characters from a string. The first argument is a path to a file. The file contains the source strings and the characters that need to be ...
6
votes
2answers
72 views

String sequence in Haskell

Given a string sequence and a string, the function should output the next string of that sequence. For example, for sequence "abc": ...
4
votes
1answer
67 views

Matching strings

Basically I solved this question on one of the competitive websites: Given the total n number of String on first input, n input follows: We have to find such pairs of string (i,j) such that ...
-3
votes
1answer
53 views

Compare counts of string occurrences

Knowing my solution ... Return True if the given string contains an appearance of "xyz" where the ...
3
votes
0answers
48 views

String sequence in ES6

Given an unique string that represents a sequence of characters, the class should implement three methods (getNextChar, getNextString and the genSequence generator). How it works We give a sequence ...
3
votes
1answer
63 views

Checking for uniqueness within a string

I saw this interview question in the book Cracking the Coding Interview: Implement an algorithm to determine if a string has all unique characters The authors solution uses bit-shifting for a ...
4
votes
3answers
196 views

Confirming existence of lapindromes

The following description is taken from CodeChef.com's Lapindrome problem. Lapindrome is defined as a string which when split in the middle, gives two halves having the same characters and same ...
6
votes
4answers
398 views

Conversion of hexadecimal string to string

Given a C# string which is a set of hexadecimal numbers such as: string HexString = "202048656c6c6f20576f726c64313233212020"; Where those hexadecimal numbers ...
0
votes
1answer
91 views

Immutable C++ String class

I have project where I will need to create lots of immutable strings. If I am using std::string, which has huge overhead - about 60-70% against ...
1
vote
1answer
61 views

Getting the individual digits of a number

Approach 1: Repeated division-modulus operations: ...