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
2answers
24 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
118 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
60 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
113 views

Extracting a Decimal from a string

I have the following method which extracts a decimal value from a string. ...
1
vote
1answer
60 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
52 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
0answers
29 views

Strip non [A-z|0-9|.|_] from string? [closed]

Input ^#%foo.bar#%#%canhaz%# Output foo.bar#%#%canhaz Function (attempts 0-1) ...
2
votes
1answer
145 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
256 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
48 views

String reverse function

Are there more optimization possible in this code to achieve better performance and minimal memory usage? ...
4
votes
1answer
71 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
174 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
63 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
61 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
37 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
50 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 ...
3
votes
0answers
19 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
498 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 ...
6
votes
1answer
87 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
75 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
281 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
43 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
60 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
45 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
45 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
60 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
33 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
55 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
73 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
133 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
110 views

C-string appender for buffers and strings

Is this C appender safe, and reasonably optimal? ...
12
votes
4answers
534 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
35 views

Stripping leading tab of each line from a file

I've got this Python code: ...
5
votes
3answers
100 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
42 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
46 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 ...
2
votes
0answers
25 views

Storage policies

I often come across situations where a library component needs to buffer a large amount of data for later processing. The problem is that at the design stage a choice needs to be made as to whether to ...
4
votes
4answers
114 views

Extremely simple character manipulation

Given a string, this code Multiplies odd numbers Subtracts even numbers, do nothing if only one even number is found Turns uppercase letters to lowercase and vice versa I think this code is too ...
2
votes
4answers
86 views

Palindromes with stacks

I'm creating a simple function to verify whether or not a string is a palindrome, and must use stacks in solving it. ...
4
votes
2answers
131 views

Function to get top k words in a given String

This is a two-part job: to identify a word to find the top k words I've tried to use regex to split but it's taking 10x more time when string is really long. ...
3
votes
2answers
45 views

Transform a string into an array based on grouping rules

I've got a simple spec for defining character sets, ranges, or wildcards. I'd like to take the string and appropriately create an array based on these rules. I have a solution but I'm sure there is a ...
3
votes
1answer
143 views

Reversing the lines of file

I have written a program to reverse the lines of a file. I made use of the String [] approach with the String.split(separator) ...
2
votes
5answers
88 views

CCC Rövarspråket (Pig Latin) translator

I have a challenge: In Sweden, there is a simple child's game similar to Pig Latin called Rövarspråket (Robbers Language). In the CCC version of Rövarspråket, every consonant is replaced by ...
10
votes
3answers
210 views

Empty Line delimiter, single line output

I'm used to only processing, at most, one line of a file at a time. This is my first time changing the delimiter, and the objective here is to take a file containing lines such as: ...
1
vote
0answers
29 views

Efficient Strip Special Characters

I have a private function in PHP that takes a given URL string and just leave the Alpha or numeric and certain punctuation left. I need the stripping of string due to having it match against ...
6
votes
2answers
112 views

Grouping An Array of Strings into Anagrams

Ok, so this code works perfectly, however, I've not coded in Java for a long time, so I'm worried about breaking Java conventions, but even more important, I would appreciate any comments on making ...
3
votes
2answers
107 views

Log-reading & String-matching with hashtable for fastest execution speed

I'm currently enjoying this exercise I'm working on for fun: I wish to write optimized code for the searching of particular strings per line in a (very large) file, counting how many exist, and ...
2
votes
1answer
37 views

Date-filtering function

Please check if this date filtering function is inefficient code. It seems so to me, but I can't figure out the other way around it. ...