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
3answers
179 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
323 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 ...
0
votes
0answers
12 views

Text not centering (Java, awt.Rectangle, awt.Graphics) [on hold]

if anyone wants an excuse to always back up your computer, let programming be it. While making a game, I thought I should separate my project into the core game and the main menu. I'll see how that ...
4
votes
3answers
55 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, ...
1
vote
1answer
29 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
91 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
181 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 ...
-1
votes
0answers
16 views

Longest Triangle Path [closed]

How can I find the path of each number that returns the largest route? ...
3
votes
1answer
46 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
214 views

Find common characters

Given two strings, find the common characters. Is there better implementation for this problem? ...
3
votes
2answers
70 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
182 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
134 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
70 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
123 views

Extracting a Decimal from a string

I have the following method which extracts a decimal value from a string. ...
2
votes
2answers
87 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
56 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
152 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
263 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? ...
4
votes
1answer
84 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
194 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
73 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
65 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
52 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
26 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
509 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
115 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
79 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
302 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
45 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
64 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
52 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 ...
1
vote
1answer
72 views

Checking whether one string is a rotation of another

Given a method isSubstring, two strings s1 and s2, check whether s1 is a rotation of s2 using only one call to isSubstring. Any comments on the code below? I would like to check the complexities ...
-2
votes
1answer
34 views

Conditionally splitting a string [closed]

My requirement is: dest = comp ; jump // Either the dest or jump fields may be empty. If dest is empty, the "=" is omitted; If jump is empty, the ";" is omitted. So I may have something like ...
2
votes
1answer
27 views

C function delimiates strings using a single character array

I am a complete noob to C and I've shied away from using such a powerful language due to it's large learning curve and other complicated mechanisms. For my first minor project I plan to create a small ...
2
votes
4answers
56 views

A function that reverses a string of characters

My problem is in writing a function reverse(s) that reverses the character string s, a line at a time. My code here works, I ...
3
votes
1answer
85 views

Python Longest Repeat

I am trying to find the longest repeated string in text with python, both quickly and space efficiently. I created an implementation of a suffix tree in order to make the processing fast, but the ...
2
votes
4answers
142 views

Java String search and replace [closed]

I would like to search a String, and for a certain word, I would like to change only the first 3 letters For example: This is a java institute which insures ...
2
votes
4answers
113 views

C-string appender for buffers and strings

Is this C appender safe, and reasonably optimal? ...
12
votes
4answers
541 views

Generating an ordinal number for the day of the month

I am relatively new to programming and came across an if statement that I believe to be a bit verbose. I have tested my code and it appears to work without any ...
1
vote
1answer
36 views

Stripping leading tab of each line from a file

I've got this Python code: ...
5
votes
3answers
105 views

Project Euler #8

I was doing Project Euler #8, which asks: The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × 8 × 9 = 5832. ...
3
votes
1answer
45 views

Acquiring indices for anagrams of an input string

I am working on an interview question from Amazon Software: Design an algorithm to take a list of strings as well as a single input string, and return the indices of the list which are anagrams of ...
4
votes
1answer
50 views

Binary Digits to ASCII Characters

I wrote this code, as a novice a to Prolog, for a challenge posted on /r/DailyProgrammer. The formal description of this challenge, as presented in the prompt reads: Input description On ...