A string is a sequence of zero or more 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
70 views

Char string review

#include "stdafx.h" #include <iostream> using namespace std; int main () { for (int i = 0; i <= 3; i++) //give the user 4 guesses at the word. { std::string guess; ...
4
votes
1answer
61 views

A boolean expression parser, written in Java

I was trying to write some of the Haskell list functions into Java, and I realized that one of the key strengths for many of the functions was the ability to pass in a boolean expression. I decided to ...
2
votes
0answers
47 views

String algorithms and locale

I am trying to write some string algorithms which I want to work for any kinds of strings and/or locale. I managed to get some results that do work, but I am not sure that what I am doing is idiomatic ...
3
votes
1answer
37 views

Printing all strings in a Boggle board

I am trying to print all the strings given in a N x N Boggle board. Its basically a N x N scrabble-like board where words can be made from a position - horizontally, vertically and diagonally. Here ...
6
votes
3answers
90 views

Dynamic Strings in C

I wrote this code for dynamic strings and would like to know what mistakes I've made. It's just a struct that gets filled on the first call to ds_allocate and freed on the first call to ds_free. It ...
6
votes
3answers
68 views

Can this FindString function be optimized further, in terms of speed?

int FindStr(char* str, int strsize, char* fstr, int from) { for(int i=from, j=0; i<strsize; i++) { if(str[i]==fstr[j]) j++; else {i-=j; j=0;} ...
2
votes
0answers
33 views

Determine if a word can be constructed from list of subsets - follow-up

I have reworked my code as suggested from my previous question: Determine if a word can be constructed from list of subsets. Please instruct me on the complexity along with a review feedback, as ...
3
votes
1answer
41 views

Escaped explode/implode function

I had a somewhat interesting issue. I had to take an array and turn it into a string with a set of delimiters; then later on take that string and turn it back into an array, splitting at the same ...
3
votes
2answers
62 views

Reading in a file and performing string manipulation

In a question I answered I posted the following code: #include <iostream> #include <fstream> #include <algorithm> #include <sstream> int main() { fstream ...
2
votes
2answers
103 views

Determine if a word can be constructed from list of subsets [closed]

The question is explained well by examples in the comments below. Also I request verifying complexity: O( n * n!), where n is the number of words in the subsets. Review my code for optimizations, ...
2
votes
2answers
94 views

Should I create an empty string and append through a foreach loop or should I use StringBuilder? [closed]

Here's the current code: static string GetResources(string header, string filter, string resourceTemplate) { string themeName; if (!TryGetHeaderValue(header, "theme", out ...
-2
votes
2answers
85 views

Compressing a string

The task is to compress a string. eg. "abcbcdabcbcd" Here as you can see some characters are repeated, so it can be compressed. "abcbcdabcbcd" -> "(a(bc2)d2)$" '$' denotes end of string. My code: ...
3
votes
4answers
110 views

Decompressing a string

We are given a string which is compressed and we have to decompress it. eg. "(a(bc2)d2)$" '$' indicates end of string "(abcbcd2)$" "abcbcdabcbcd" This is the final string. My code: import ...
3
votes
3answers
95 views

Small function for getting character value

I want to extract some values in i-commas(") from lines like this: <P k="9,0,1" vt="191" v="100.99936" z="" /> Example: getCharVal ( cp, char "k=\"", 9) where cp is a pointer the line ...
2
votes
2answers
116 views

Improving code to compute hash of string

I want my code to be reviewed and I'd like to hear your opinions. Sun's code to compute hash of string: public int hashCode() { int h = hash; if (h == 0 && value.length > 0) { ...
3
votes
2answers
86 views

Count byte length of string

I am looking for some guidance and optimization pointers for my custom JavaScript function which counts the bytes in a string rather than just chars. The website uses UTF-8 and I am looking to ...
5
votes
6answers
190 views

Reversing words in a string

I have to reverse the string "He is the one" to "one the is He". I have written some programs in Java but am looking for other best solutions. Suggest any possible ways to minimize the current ...
4
votes
3answers
100 views

Number aware string sorting with comparator Java

I have this class for use in sorting strings such that if strings have a number in the same position it will order the numbers in increasing order. Alphabetical gives: file1 file10 file2 What I'm ...
9
votes
2answers
107 views

C String - new function to detect user's anger - thoughts?

This was the most humerus coding I've ever done. It's for my string library in C. It detects if the user is angry to various degrees, namely str_isHeated(). Why? Ever play a text-based game and ...
2
votes
3answers
65 views

Sorting strings in a one dimensional array

What are the better solutions possible? I have a character array with different strings. There is a max size for the strings. In case a string is smaller than max size remaining places are filled ...
3
votes
3answers
132 views

String Extension improvement

I am creating a string extension to validate some input. My scenario is when we have a string it will format it according to following guideline. If the sample string is “One Two Three Four Five” and ...
8
votes
4answers
398 views

Return a string without the first two characters

I'm new to Java and am trying to solve a scenario. Even though I've succeeded and it works, I've just wondered if there was a more practical way of doing this task. Is there a quicker or more ...
4
votes
1answer
41 views

Find common preamble of a list of strings

Think of a set of text lines starting with a common string, e.g. indented code. my $preamble = reduce { my $len = min(length $a, length $b); --$len while substr($a, 0, $len) ne substr($b, 0, ...
2
votes
1answer
114 views

String Matching and Clustering

I have a pretty simple problem. A large set of unique strings that are to various degrees not clean, and in reality they in fact represent the same underlying reality. They are not person names, but ...
4
votes
2answers
148 views

Streambuffer and string manipulation

One of my colleagues told me that you can use streambuffer for std::string, and instead of using string id in the for loop, you can declare it outside. I am not sure whether this will make any ...
1
vote
1answer
51 views

Getting limited user input, with echo

I've written a code snippet that will get a (max.) 14 character string from the user input, and while the user is typing, simultaneously echo it out to the screen. It seems a bit long and ugly, so I ...
5
votes
1answer
110 views

Shortest distance from one word to another. eg: cat -> cot -> dot -> dog

Lil' preparation before the interview. This is my solution to the problem in title. The code is pretty straight forward. Requesting suggestions for improvement and also verification of complexity, ...
8
votes
1answer
147 views

Adding N characters to a string

I need to preprend N spaces to a string to make it 10 characters in length. I came up with the following method, but since it is going to be called often, I want to ensure it is optimized. Could this ...
2
votes
1answer
54 views

C String Processing — magnet link example

I'm trying to get my head around C-string processing. I've decided to try my hand at making a dirt-simple magnet link generator. The format that a magnet link needs is ...
16
votes
6answers
935 views

How can I make this mess of Java for-loops faster?

I'm trying to find all the 3, 4, 5, and 6 letter words given 6 letters. I am finding them by comparing every combination of the 6 letters to an ArrayList of words called sortedDictionary. I have ...
5
votes
1answer
82 views

First attempt at dealing with command-line args

A little while ago I was fiddling with dependency-injection and came up with this small WPF application that I can launch with command-line arguments. Not only this was my first experiment with DI, ...
3
votes
2answers
49 views

vb.net select case string comparison

I have a select case that checks against a string variable. Its starting to get large and I am wondering if there is a better way of doing this? Here is a smaple of the select case: ...
2
votes
2answers
66 views

Assigning list index values to String

I am just trying to convert each list of values to String by index one by one. My Code is running fine. But I am thinking that I can write better code than this. I Need your good coding possibilities ...
-1
votes
2answers
162 views

Code review: infix to postfix converter [closed]

public static StringBuffer infixToPostfix(StringBuffer infix) throws InvalidCharacterException { StringBuffer postfix = new StringBuffer(""); Stack<String> myStack ...
2
votes
3answers
200 views

Longest DNA sequence that appears at least twice (only one DNA string as input)

My question is to find the longest DNA sub-sequence that appears at least twice. The input is only one DNA string, NOT TWO strings as other LCS programs. I have done my 4th program and it seems to be ...
2
votes
1answer
96 views

Finding largest string palindrome

I've attempted to write a program to find the largest palindrome in a sentence. Spaces are included and characters are case-sensitive. Can you suggest better ways of doing this? //public static void ...
-3
votes
2answers
48 views

Replacing parenthesis in code [closed]

I am trying to write a string or integer formula which will look for code between parentheses. My logic is this: Search for the first parentheses, find the last parentheses, and return everything in ...
1
vote
2answers
67 views

strstr implementation

Please review my strstr implementation. This is an interview question that does not allow the use of strlen(). Is there a better way than using a boolean below? #include <iostream> #include ...
0
votes
1answer
73 views

Processing a string from the console

How can I make this program run faster? On enter, I have a string from the console. For example: 1 1 7 3 2 0 0 4 5 5 6 2 1 On exit, it will be 6 20 Could you recommend a way to make this run ...
3
votes
2answers
97 views

Successful Encoder and Decoder for messages

I recently wrote a code for a encoder and decoder that works off of a key and the only way to decode the message is with this program and the case-sensitive key. I have yet to incorporate punctuation ...
0
votes
2answers
49 views

Building a string made easier?

I have these lines of code in my view: <?php $count = count($product->getTags()); $tagsStr = ''; foreach($product->getTags() as $key => $tag){ $tagsStr.= " " . ...
5
votes
6answers
289 views

Cleanest way to place values into strings

I am trying to standardize the way I write code. Which is the best way to place the values into a string, method 1 or 2? string myCat = "persian"; // Method 1 Console.WriteLine("I have a wild {0} ...
1
vote
1answer
39 views

Calculating the Hamming distance

That's an easy one. I just want to calculate the Hamming distance between two strings. function hamming(str1,str2) local distance = 0 -- cannot calculate Hamming distance if strings have ...
2
votes
5answers
168 views

Improve if-statement for multiple strings

I working with a lot of Strings which I get from a web-form: final String user = request.getParameter("user"); final String pw = request.getParameter("password"); final String name = ...
0
votes
1answer
58 views

Please critique my Python remove_prefix and remove_suffix functions

If the prefix/suffix does not match the beginning or the end of a string, then, depending on how I call these functions, they should either raise an exception or return the original text unmodified. ...
2
votes
3answers
118 views

Retrieving doubles from string - simple problem

The problem is not very complicated (I mean it is easy to solve it), but the question is how to make it in the easiest way (Java) Input String: String inputString = ...
1
vote
3answers
98 views

Review of three constructors for a String class

I have the following declaration in my String.h file: private: char* nstring; int nlength; }; The following are three constructors I've implemented in String.cpp. I would like these to be ...
-1
votes
1answer
53 views

Can someone review my string compare method I wrote? [closed]

Can someone review this method? It's not working when I compare a null terminating string with a regular char array like '\0' with 'a', 'b', 'c' // Compares the two arguments. If they are equal, 0 ...
1
vote
2answers
137 views

Performance: getting first value from comma delimited string

I've got a string that has values that are delimited by comma's, like so: $var = '1,23,45,123,145,200'; I'd like to get just the first value, so what I do is create an array from it and get the ...
0
votes
2answers
131 views

Run-length encoding using C / C++

This is my first post on Code Review. I have already asked this question on Stack Overflow and was asked to post it here. Here is the link. Recently I was asked in an interview to convert the string ...