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.
3
votes
2answers
81 views
Is there a circular reference in a set of template substitutions?
I have a configuration engine that allows the user to specify a dictionary with text templates (read from a JSON file) where each placeholder like {x} can be ...
4
votes
0answers
24 views
Rust: Replace string in file
This is my first module I wrote in Rust. I'm new to the language and couldn't find a way to easily replace some words in a file, so that's my go at it. If there's already something like that and I ...
1
vote
0answers
25 views
Nand2Tetris Hack Assembler
Now I know the same type of question (same task) has been asked on this site before, but I recently wrote my C++ implementation of the Hack Assembler from the Nand2Tetris Chapter 6 course (defined ...
1
vote
0answers
30 views
Find largest substring which repeats to yield entire string
My job is to find the largest repeating substring in a given string, which repeats to re-create the entire string. For example, if input="cdcdcdcd" then the longest pattern would be "cdcd". If no ...
3
votes
1answer
38 views
A simple implementation of a mutable String in C
The following code implements a simple interface to operate on mutable* Strings in C. It is composed of two files: one for the structure definition and the ...
4
votes
2answers
47 views
Split a character string based on change of character
I am contributing a solution to the following task on Rosetta Code:
Task
Split a string into comma (plus a blank) delimited strings based on a change of character (left to right).
Show the ...
5
votes
1answer
31 views
Convert a password to a phonetic string for end users
As much as I hate it, sometimes providing passwords to people has to be done electronically. When I do that I try to remove any ambiguity that might be created by the font, user etc. and provide a ...
0
votes
0answers
24 views
Composing a sentence with conditional template parameters [closed]
I am trying to generate the following string:
*Calls a taxi to ROOM_NAME_HERE [ROOM_ID_HERE] [-COST_CREDITSc, -COST_PIXELSpixels]*
With the parameters such was ...
3
votes
1answer
40 views
Extract index of first unique element in large array in Swift
I'm using the following code to return the first index of a unique character in a large String. It works fine until I get to large strings, where it times out.
Is ...
3
votes
0answers
40 views
anagramDetection.js
A function that accepts two parameters, a parent and a child string. Determines how many times the child string - or an anagram of the of the child string - appears in the parent string.
...
9
votes
2answers
78 views
StringBuilder in C v2: Not a charged dance
A follow-up on this. To quote by copy/paste:
Lots of languages have something that lets you build up a dynamically-sized string with minimal overhead. C doesn't, and I found myself using code that ...
3
votes
0answers
32 views
With 2 sets of strings, find a string that can be constructed from either set
Given the following sets of strings:
are yo
you u
how nhoware
alan arala
dear de
I need to find a sequence that can be constructed by concatenating the strings ...
3
votes
1answer
46 views
Simple program to split arguments up
I am writing this small tester program to be used as part of a larger project, and I am quite unsure about the strtok function, which I (think) I need to use to ...
6
votes
1answer
64 views
Avoiding shell injection when calling Git in Python
I'm developing a command line application in Python which processes information that users provide. I've been reading the Python documentation on this topic and found that the built-in module ...
2
votes
1answer
39 views
Return a string based on Type, Color and Position
I recently wrote a really long one-liner, it was really just for fun, but I would like to know if it's bad practice or not. Can you tell me?
Here's my full class, but it's about the ...
4
votes
1answer
66 views
String permutations
So I have tried the famous string permutation algorithm.
Example for those who are not familiar with the algorithm:
ABC -> ...
2
votes
1answer
58 views
String “Contains” char function
I wrote this function which does the following from scratch w/o looking for ways that it is typically done:
Accepts a char c to search for.
Accepts a ...
3
votes
0answers
29 views
KMP string-matching algorithm implementation
This is Knuth-Morris-Prat algorithm implementation to check if a pattern is present in a larger text, and if it does the algorithm returns the start index of that pattern, else -1. It starts off by ...
12
votes
4answers
885 views
Delete rows in spreadsheet where cells match some patterns
I have vba code that loops through a large number of records and deletes rows based on criteria. The issue at hand is that it takes far too long to run. I have never actually let it finish because it ...
4
votes
1answer
51 views
Peter Norvigs spellcheck in Rust
For a Rust project I'm working on I needed a (simple) spellcheck algorithm and I set out to re-implement Peter Norvigs spellcheck algorithm in Rust.
...
6
votes
1answer
55 views
Transposing characters in a string
I want to create a function that takes a string and returns an array of versions of it in which always one pair of characters is transposed (swapped).
I came up with this:
...
3
votes
1answer
72 views
StringBuilder in C
Lots of languages have something that lets you build up a dynamically-sized string with minimal overhead. C doesn't, and I found myself using code that did that manually in a couple of places, so I ...
5
votes
0answers
39 views
Concatenating strings into a fixed-size char array in C
Using the standard C library, I want to repeatedly concatenate onto a fixed size string. Despite it's promising name, the semantics of strncat do not appear suited ...
1
vote
1answer
96 views
Codewars “Consecutive strings” kata
The challenge description is as follows:
You are given an array strarr of strings and an integer k. Your task is to return ...
6
votes
2answers
368 views
Interleave two strings
This program is designed to interleave two strings, which are input as command line arguments. I'd appreciate any feedback as I am new to C and self-taught.
Edit: Since this is an exercise in ...
1
vote
1answer
34 views
malloc and free of a char-array
I wrote a function to reverse a char-array (string).
Since I'm beginner and didn't work with malloc and stuff before, maybe someone could take a look, if this is ...
-2
votes
0answers
57 views
Inverted Index implement in java on the Hindi text file
Creating Inverted index in java
This code tested on three document to created index.
Please review it.
Data structure used:
Hashmap, HashSet, Array ,etc.
...
3
votes
0answers
41 views
Hackerrank: Sherlock and anagram (optimal time complexity)
Problem statement
Given a string \$S\$, find the number of "unordered anagrammatic pairs" of substrings.
Input Format
First line contains \$T\$, the number of testcases. Each testcase ...
15
votes
9answers
1k views
Repeatedly eliminate a substring
I'm trying to pass a programming challenge where we are to replace all instances of a substring in a string until there are none left. So an input like
...
2
votes
0answers
29 views
Code for sanitizing a string for input into MySQL queries
This code takes an input string, the string length, an output buffer, the maximum capacity of the buffer (in elements, not bytes) and returns true if sanitization succeeded; false otherwise.
Is this ...
2
votes
1answer
62 views
string-length, structs, pointers in c
So since I'm just new with learning C (this is the second day now), I'd be very happy if someone could review my code:
what I tried to do is:
create a structure containing a string- and a length-...
7
votes
4answers
935 views
Storing Enum values as Strings in DB
I have a Data First Migration and have been struggling a little with storing an enum value as a string.
(Im aware that enums should be stored as ints but, personally I have never liked this, yes ...
3
votes
2answers
79 views
Leetcode 49: Group Anagrams - Hash function design talk
problem statement
Given an array of strings, group anagrams together.
For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"],
Return:
[
["ate", "eat","tea"],
["nat","...
7
votes
3answers
1k views
String comparison using pointers
This piece of code works fine. But I'm wondering if it can be done in a more efficient way. More specifically, this part (*(s1 + i)) if it possible to force it to ...
3
votes
2answers
67 views
Order line reversing (reversing line order)
I'm a student learning to code in C. I had to make a program for class to reverse lines of input from the keyboard (not character wise, but reverse the order of the lines input).
The program is ...
1
vote
2answers
91 views
Python one-liner to print permutations of a string
I have written a Python one-liner that permutes a given string. I wrote this just for fun using list comprehensions and I would like to get feedback from the community.
...
1
vote
1answer
34 views
Parsing string into hash-map with 2D coordinates as keys
I had never programmed in a functional programming language before. I think that this function has large nesting. Is there way to rewrite it better? I am most worried about the use of "flatten". Is ...
4
votes
1answer
95 views
Checking if string contains other strings
This is simply an extension method which checks if a string str contains all the values in values.
However, there are cases ...
2
votes
1answer
72 views
Truncate text to some number of words when clicked
I am currently using the code below to truncate text:
...
0
votes
2answers
31 views
Targeting string to wrap with HTML element to italicize
Objective
I set up my page to dynamically wrap <i> tags around a targeted keyword (string) on a title.
Background
When I worked on the static parts of the ...
3
votes
3answers
98 views
Counting letters, words, etc. in the input
I'm trying to learn some coding to broaden my scope of knowledge, and I seemed to have run into a bit of a conundrum.
I'm trying to create a program to output the number of characters, digits, ...
3
votes
1answer
89 views
Determine if two strings with unrecognized letters are from the same text
Given two strings S and T of N=>1 and M=>1 characters, respectively, with unrecognized letters (an unrecognized letter is marked by "?", for brevity, every group of K consecutive "?" characters is ...
2
votes
2answers
99 views
Splitting strings in Java
I wrote a function which takes in input a list of strings that is splitted by comma. Then each generated string is trimmed.
Example:
...
1
vote
0answers
113 views
Hackerrank: Sherlock and anagram
Problem statement
Given a string \$S\$, find the number of "unordered anagrammatic pairs" of substrings.
Input Format
First line contains \$T\$, the number of testcases. Each testcase ...
8
votes
2answers
90 views
Short and Messy Polybius Square
I attempted to recreate the Polybius square, also called the Polybius checkerboard, which was used in Ancient Greece for cryptography. Since it is an uncommon cipher, it is nowhere on Code Review.
...
1
vote
1answer
54 views
Find and print all numbers in a comma-delimited string using sscanf
I want to find all of the whole numbers in a string that starts with { and ends with }, and uses ...
2
votes
1answer
73 views
String similarity algorithm (c++) [closed]
Parameters:
first - the first string.
second - the second string.
similarCharacters - ...
6
votes
2answers
71 views
Printing mutual anagrams
Question:
An anagram is a word that can be written as a permutation of the
characters of another word, like "dirty room" and "dormitory"(ignore
spaces). However, "the" and "thee" are not ...
2
votes
1answer
66 views
Vector-based Null Cipher
Continuing with my series of cipher programs, I hastily wrote a null cipher program, and I was wondering how it could be improved:
...
7
votes
1answer
127 views
A Moses's worthy string splitter
I am trying to perfect my string splitter's performance, to be more fast, more easy to maintain if someone else reads it and more readable code-wise.
Context ,Scope and Objectives
Where I work we ...