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)

1
vote
0answers
19 views

Select type stringification for ostream output using C++11 template mess

The objective is to select which function is used to represent a type as a string for output on ostreams. The code here allows to explicitly choose a function, or to fallback on a java style ...
1
vote
0answers
41 views

Word separator and Pig Latin program - final edit

This is an updated version of my previous Java program that asks the user for a sentence and then separates the words and then converts the sentence into Pig Latin. My previous program was working, ...
5
votes
3answers
200 views

Using recursion to count substrings (with exceptions to the rule) in Java

I am going through the CodingBat exercises for Java. Here is the one I have just finished: Given a string, compute recursively the number of times lowercase hi ...
7
votes
1answer
88 views

Equation parser and solver

I wrote this equation parser and solver, I feel like it is well documented and tested: ...
4
votes
1answer
52 views

Finding common elements, ignoring duplicates, in two given string arrays

I am going through the CodingBat exercises for Java. Here is the one I have just completed: Start with two arrays of strings, a and ...
2
votes
1answer
47 views

Replacing all occurrences of a substring in a string without using regex

Problem Statement: Given two strings, base and remove, return a version of the base string where all instances of the remove string have been removed (not case sensitive). You may assume that ...
2
votes
2answers
60 views

Parsing a single CSV line into a list of strings

I've written this method to replace an older method that was much simpler, but used the regex split method and couldn't tell if a comma was in quotes/brackets/etc. and didn't read double quotes as ...
2
votes
1answer
36 views

Word ladder solution in Java using matrix

Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that only one letter can be changed at a time and each intermediate ...
1
vote
1answer
22 views

Splitting a string basing myself on categories

I was thinking about splitting a string based on certain categories, for example alphabetic and numerical, lower and upper case, and even the 3 lines of the keyboard. I wrote a generic function for ...
5
votes
1answer
45 views

Prefix- and z-functions in C++ (string algorithms)

Let us define prefix-function(string)[i] as the length of the largest prefix of string, which is also a suffix of ...
3
votes
2answers
84 views

Suffix array construction in \$ O(n \log^2 n) \$

Here is my implementation of the suffix array construction algorithm which follows this paper (specifically, pages 4 and 6). ...
0
votes
1answer
22 views

Word Counting from Array onto Output File [closed]

For this problem, I have to have two text files: one for list of words that need to be found and other containing the document that needs to be search. The results would placed in a output "results" ...
3
votes
1answer
83 views

Split string by substring without using String.Split()

The Aim Since I very rarely write code to do things other than business logic anymore I've set myself a challenge: Split a string into a list of substrings by splitting on a matching string, without ...
3
votes
4answers
477 views

Validating Firstname and Lastname

I have written some code in Java that checks if the strings Firstname and Lastname are valid names. These are inputted by the ...
12
votes
2answers
389 views

Split string in half and change case accordingly

I found the following challenge online: Create a function that takes a string and returns that string with the first half lowercased and the last half uppercased. eg: ...
3
votes
3answers
207 views

More portable toLower() implementation

I am challenging myself to try to attempt to write a function that is as efficient, portable and failsafe as possible. The function is very simple and just converts a ...
6
votes
4answers
370 views

Summing digits of an alphanumeric string

I am going through the Java CodingBat exercises. Here is the one I have just completed: Given a string, return the sum of the digits 0-9 that appear in the ...
4
votes
3answers
62 views

Case insensitively removing a substring, efficiently

I am going through the CodingBat exercises for Java. I have just completed this one: Given two strings, base and remove, ...
2
votes
1answer
34 views

Repeated string concatenation

I've been looking for a way to have a predicate that establishes that all elements of a list are substrings delimited by a given string. Analogues in other languages include: ...
-2
votes
2answers
29 views

Extracting first initial and last name [closed]

How can I do this better? $a = "Tom Smith" ; $e = $a.substring(0,1) $ee = ($a).split(" "); $y = $e + $ee[1]; $y TSmith
1
vote
4answers
95 views

Redacting everything in a string except a particular word

I am working through the Coding Bat exercises for Java. Here is one I have just completed: Given a string and a non-empty word string, return a version of the original String where all chars have ...
6
votes
2answers
193 views

Removing Asterisks and neighbors from a string

I am going through the CodingBat exercises for Java. I got to this problem: Return a version of the given string, where for every star (*) in the string the star and the chars immediately to its ...
3
votes
1answer
50 views

A trivial command line utility for trimming whitespace from lines in C

I was practicing some C and decided to write this simple command line utility for stripping leading and trailing white-space characters. Note: see the next iteration at A trivial command line utility ...
5
votes
3answers
219 views

Find common characters

Given two strings, find the common characters. Is there better implementation for this problem? ...
3
votes
2answers
73 views

Simple string hashing algorithm implementation

I thought of a simple way to hash a string. By taking the ASCII decimal value of each character, multiplying it by 10, and adding all of the values computed together for each character in a string. Is ...
5
votes
1answer
190 views

Counting occurrences of substring in string

I need to know how many times a substring occurs in a given string. I figured that I might as well create an extension method: ...
1
vote
2answers
38 views

Counting length-2 substrings that are common to two strings at the same offset — Python

I solved the CodingBat task: Given 2 strings, a and b, return the number of the positions where they contain the same length 2 substring. So "xxcaazz" and "xxbaaz" yields 3, since the "xx", ...
5
votes
2answers
140 views

Counting length-2 substrings that are common to two strings at the same offset

I am working through the CodingBat exercises for Java. I just completed this one, an exercise that requests the comparison of substrings of two strings: Given 2 strings, a and b, return the number ...
4
votes
2answers
71 views

Text files: Copy, Rename, Append/Merge together

I wrote 3 subroutines related to batch data processing, they will be used together. A bit of background, I wrote this for my admin colleagues who do not write code. An application dumps daily ...
2
votes
2answers
129 views

Extracting a Decimal from a string

I have the following method which extracts a decimal value from a string. ...
2
votes
2answers
91 views

Converting file from Markdown-like markup into HTML using repeated substitutions

The following code reads a file, splits its data, replaces some characters in the data, and then joins the data again (I added more details in the comments): ...
4
votes
2answers
60 views

Iterating over the lines of a stream

This structure is supposed to iterate over the lines of an input stream, using std::getline. Any remark is welcome! ...
2
votes
1answer
155 views

Maybe getting a character from a list of strings

I'm trying to transition from JavaScript to PureScript (a Haskell spinoff that transpiles to JavaScript). For starters I coded this: ...
4
votes
2answers
266 views

Evaluating an expression with integers, +, and *, as well as -, /

There is a job interview question, and the source of the question is here. The solution is pretty simple. We just need to split the input string by + and then by *. Then we compute products in a ...
1
vote
1answer
55 views

String reverse function

Are there more optimization possible in this code to achieve better performance and minimal memory usage? ...
5
votes
1answer
87 views

Cleaning a WPA wordlist

I have a short bash script that processes gigs and gigs of data. I am looking for any improvements to make it faster. This is my very first bash script so please be gentle. I am really only ...
6
votes
2answers
197 views

K&R exercise 1-19: reversing each line of input

This is my solution for exercise 1-19 of K&R: Write a function reverse(s) that reverses the character string s. Use it to write a program that reverses its input a line at a time. It works, ...
5
votes
2answers
74 views

Knuth's Word Wrap Algorithm in Haskell

I put together a Haskell function for Knuth's word wrap algorithm. A simplified version of the algorithm is described here. I've already been told that there are certain aspects of my style that are ...
2
votes
1answer
70 views

Finding the common prefix in a list of strings

Given a list of strings, my task is to find the common prefix. Sample input: ["madam", "mad", "mast"] Sample output: "ma" ...
2
votes
1answer
38 views

Python function to strip inline repr'd unicode strings

I have to write a python function that takes a string that contains raw unicode strings (e.g. "u'hello' there") and transform it into a string that strips the ...
3
votes
1answer
54 views

Searching for a substring in a ring queue

I am implementing a function which searches through a ring queue for a given substring. The function returns true if the substring is found, otherwise false. There is a cell containing null between ...
4
votes
0answers
27 views

Perform a contains-ignore-case with multiple search-tokens

I had a look on Stack Overflow etc. on how to perform a contains ignore case with n given strings. Most answers suggested using regex for this task. Although it's a valid option, I prefer doing ...
14
votes
2answers
513 views

Python-like C string library

Most of the C code I have written has never been seen by anybody else, and I wonder if my code follows normal practices, especially how my code performs security-wise. The code is for a library that I ...
10
votes
2answers
123 views

Lazy String.Split

C#'s String.Split method comes from C# 2.0, and lazy operations weren't a feature back then. The task is to split a string according to a (single) separator. Doing ...
7
votes
1answer
80 views

Formatting an ID string

I'm working with an API which gives me 19-digit ID numbers, formatted in blocks of four except for the last 3 digits. While I tried a for loop, I thought it would be most efficient to simply use a ...
8
votes
4answers
317 views

Checking if a string is a pangram

This checker works perfectly but I have a strong feeling that I could make this script much more compliant with the "Zen of Python", especially having read a book about it recently. There is no doubt ...
2
votes
1answer
52 views

Converting a string to a corresponding type in JavaScript

I need to convert a string value to its primitive type in JavaScript. Other values that are not of type String should just be returned. Example: String '...
2
votes
3answers
66 views

isSubstr in C++

I'm trying to implement a function to determine if a substring is indeed a substring of a string s. This is what I came up with but I feel that there must be ...
1
vote
2answers
53 views

Edit distance between 2 strings

I have written a program that calculates the "cost" of transforming one string into another. I would like you to review it. ...
4
votes
1answer
46 views

Anatomy of a string-reversal program with less coupling

I'm currently trying to improve my C understanding. Would you mind telling me if there are good/bad things that I did here? (I implemented a function to reverse a string in place). For example things ...