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.
1
vote
3answers
83 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 = ...
-2
votes
0answers
26 views
My String compare isn't working [on hold]
// Compares the two arguments. If they are equal, 0 is returned. If they
// are not equal, the difference of the first unequal pair of characters
// is returned.
int strcmp(const char* ...
0
votes
3answers
65 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 ...
0
votes
1answer
32 views
Can someone review my string compare method I wrote? [on hold]
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
53 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
1answer
32 views
From hash to a constant string [on hold]
I would like to make this code even more efficient by writing it to a constant string, such as "_file.txt". ex: if there is a p in the query then write it into 'p' and the constant "_file.txt" so that ...
0
votes
2answers
74 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 ...
2
votes
4answers
664 views
Improving efficiency for finding longest contiguous non-decreasing substring
I was working on a problem set and I came across this problem:
Assume s is a string of lower case characters.
Write a program that prints the longest substring of s in which the letters occur ...
2
votes
4answers
64 views
C++ strings compare and assign
Would you plese run through this code and provide your comments.
void quote_container::allocate(string *i_string, string *i_value){
string temp_name = *i_string;
double temp_value;
...
0
votes
1answer
36 views
Random string generator [closed]
I have made a simple number generator, and I have a question: is it possible for the generator to eject "red", "blue", "green", " yellow" and "white" instead of the numbers 1-5?
namespace ...
2
votes
3answers
54 views
Function for encoding strings in-place
I recently wrote a function that replaces every white space with '%20', just for fun (and sharping my coding skills). The input string is terminated with extra white spaces, with the length that the ...
1
vote
3answers
46 views
How to simplify this matrix transposition of a string or make it more readable?
Per a Reddit Daily Programming Challenge, I am performing a matrix transposition on a string using JavaScript.
Example input: 'The quick brown fox jumped over the lazy dog'
Output:
Tqbfjotld
...
4
votes
1answer
54 views
Critique of Delimited String Method
I'm working my way through The Java Programming Language, Fourth Edition - The Java Series. This is Exercise 13.3:
As shown, the delimitedString method assumes only one such string per input ...
0
votes
0answers
68 views
Help me understand and improve this implementation in D of null delimited to printf %b converter
I wrote a D implementation of the nul2pfb utility from http://www.dwheeler.com/essays/filenames-in-shell.html, as the link to the source code was broken and I wanted to try to learn D. I noticed that ...
1
vote
3answers
88 views
Testing distance between characters in a string
Here is another challenge from Coderbyte. I found this one challenging, although not quite as much as the previous two I've posted. Based on the feedback I received on my earlier posts, I structured ...
0
votes
1answer
73 views
Is this the most efficient way to track word changes in a string?
I'm working on a writing platform and am using a modified version of the Levenshtein distance algorithm to track a writer's engagement with their writing. It tracks not only words added to their ...
1
vote
1answer
37 views
Simple Nick Namer Review Request
Hi guys this was my first project, I redid it after getting critique on my second project.
Can I please get some Critique on this project too?
The code is pasted in sections, but it appears exactly ...
3
votes
3answers
143 views
Is this the best way to reverse a string in C (not in place)?
Here is my code. Is there anyway to make it more efficient?
/*
IN: string to have characters reversed
OUT: string containing characters in reversed order
*/
char* reverStr(const char *str)
{
...
2
votes
2answers
29 views
Encoding strings using periodic table abbreviations
I took a JavaScript challenge to finish a task related to logo of "Breaking Bad" where letters in your first name and last name are spotted with elements of periodic table and its respective atomic ...
1
vote
2answers
105 views
Is there a neater way of concatenating string literals to make a string object?
I am passing a string object to a function like so:
somefunc( std::string("Failed to open window (") + SDL_GetError() + ") --- Quiting" )
However, I don't really like my method of concatenating the ...
2
votes
1answer
37 views
Function equivalent to strcmp
I'm starting out and need feedback in order to discover what are the things I'm doing wrong.
This is supposed to behave like strcmp:
int compare(char *str1, char *str2)
{
while(*str1 || *str2)
...
1
vote
0answers
29 views
How to increase concision and performance in a function to retrieve sentences where keywords match?
I'm building a text search system for a web application in PHP. I wrote this function that gets the sentences of the text which contains the keywords used by the user and also highlight them (well, ...
3
votes
2answers
92 views
K&R 1-20 Suggestions for Style and a better C Paradigm
I'm learning C with K&R 2nd Ed. I just completed ex 1-20 (which is the detab program). I was hoping to get some feedback on my work. I want to make sure that I am taking a good C approach and ...
1
vote
2answers
48 views
Conditional concatenation
I want to do a conditional concatenation. My issue is at the end of the for-loop. I have all variables starting with \n for removing this, and I need to strip out each variable. I think there ...
0
votes
0answers
35 views
Optimize Python string handling [duplicate]
How can I better optimize this check? It looks very lengthy.
if i >0 and ('Phone:' not in address or 'Fax:' not in address):
print 'foo'
else:
print 'bar
Also, how can I strip() \n from ...
5
votes
5answers
306 views
How can I optimize this array operation for speed in Python
I've been trying to take image pixel data and write it out into printer code and my results are rather slow.
Here is a asimplified version of what I have so far (image is a PIL Image object of 1200 x ...
4
votes
1answer
115 views
Occurrence of a word in a sentence
I have written Java code that finds the frequency of the occurrence of a word in a sentence. It is working fine. The only thing I want to do is to optimize this code.
String str = "I am a Boy I am ...
1
vote
1answer
66 views
wild card pattern matching algorithm
i was trying to write code which does a validation for below wildcards:
'?' ------> The question mark indicates there is zero or one of the preceding
element. For example, colou?r matches ...
3
votes
2answers
120 views
reading unlimited input strings in C
The idea is to write a function that reads string of unknown size from stdin, keep it in dynamically allocated array of unknown size and return copy of that array.
Is this the right approach? Could I ...
1
vote
1answer
111 views
Modifying a string by passing a pointer to a void function
Beginner here. I have two questions:
Please explain the relationship between pointers and arrays? In this tutorial, they change int c by changing *r in the function. How is that possible?
Also, ...
2
votes
0answers
35 views
Extract location from HTTP socket
I have the following HTTP reply saved in a local file called source.txt:
HTTP/1.1 301 Moved
Connection: close
Content-length: 111
Location: https://11.12.13.14:81/
Content-type: text/html; ...
2
votes
1answer
120 views
How can I get rid of SELECT…CASE and GOTO in this string formatting helper function?
A while ago I implemented .net's string.Format() method in VB6; it works amazingly well, but I'm sure there has to be a way to make it more efficient.
I'll start by listing a simple class called ...
2
votes
1answer
56 views
A more readable InStr: StringContains
Consider the following:
If myString = "abc" Or myString = "def" [...] Or myString = "xyz" Then
In C# when myString == "abc" the rest of the conditions aren't evaluated. But because of how VB works, ...
4
votes
6answers
417 views
Number of words in a string
I wrote this pretty simple program (it's an exercise from a book). It counts the words in a simple string. The book is a very old one (I think it's from 2003) and uses char arrays. Because of this, I ...
1
vote
1answer
79 views
Automatically indent a whole block of text into str.format
I wondered if there was any better way of doing so.
I had a hard time figuring it out (it seemed nobody else already tried to do so).
import re
import string
class BetterFormat(string.Formatter):
...
1
vote
1answer
71 views
Python abilities on strings
the Encoding scheme is given below:
Don't replace the characters in the even places. Replace the characters in the odd places by their place numbers . and if they exceed 'z', then again they ...
2
votes
3answers
154 views
Is there a better way of making an NSString with many argument values?
I have a form that I'm turning into a string value for an email, but the string value that I turn it into seems very complicated, plus I believe this way takes up a lot of memory and is somewhat slow ...
3
votes
3answers
328 views
Random String generator in C
I created this small function just to practice C code.
It's a simple random string generator.
#include <string.h>
#include <time.h>
char *randstring(int length) {
static int ...
3
votes
1answer
80 views
Efficient way to copy unordered String into ordered String
I'm doing this in Hadoop Java where I'm reading a String. The string is huge that has been tokenized and put in an array. It has key-value pairs but they are not in any order. I want this order to be ...
2
votes
1answer
134 views
String Interpolation / Word Matching with XML in C#
I'm working on a project where I need to map XML values to field names. Classic CS problem, I think I've got a pretty good approach but would like feedback.
For example: breachReportType matches to ...
1
vote
2answers
81 views
Custom Script Editor
I'm making my own script editor (in this case for Arma: Cold War Assault) because I want to learn and this is challenging enough.
Let me just get this out of the way: please don't tell me that I ...
1
vote
1answer
70 views
Ruby string splicer
So I came across an interesting problem awhile back, and I finally got around to solving it. Basically, it needs to allow the user to provide two words, and have them progressively splice together, ...
3
votes
1answer
81 views
Trim certain characters from a string in javascript
I want to remove not only spaces, but certain characters aswell from the beginning or end of a javascript string.
function trim(str, characters) {
var c_array = characters.split('');
var ...
1
vote
1answer
77 views
Implementation of String object as an exercise
I am reading "Object-Oriented JavaScript" by Stoyan Stefanov to learn JavaScript and in the end of the chapter named "Objects", there's an exercise that asks you to implement your own String object. I ...
1
vote
1answer
206 views
A better approach to parsing this file name in Java?
I am creating a file uploader, and one function of the uploader will parse the file name to make sure that it is in the correct format.
This is the proper format of the file name: ...
1
vote
2answers
85 views
Split and word count in go
Could it be written better?
package main
import (
"code.google.com/p/go-tour/wc"
"fmt"
)
func WordCount(s string) map[string]int {
dict := make(map[string]int)
splited := Split(s)
...
3
votes
1answer
108 views
String processing in JavaScript
We have a lot of phone numbers that contain dashes and start with a zero which are from another country.
I am trying to strip the dashes and the one leading zero and select the country code from a ...
1
vote
6answers
198 views
Remove specific consecutive element in array
I'm trying to reduce consecutive elements of array to one, but not for all values like:
{3,0,0,0,3,3,3,0,0,0} => {3,0,3,0}
but for specific one, in my example 0:
{3,0,0,0,3,3,3,0,0,0} => ...
1
vote
2answers
225 views
PHP spell checker with suggestions for misspelled words
I built a simple PHP spellchecker and suggestions app that uses PHP's similar_text() and levenshtein() functions to compare words from a dictionary that is loaded into an array.
How it works is ...
-1
votes
1answer
48 views
Java input string from .csv file [closed]
I am very new to Java and I am trying to compile "+" in the file Reactions.csv. Here's what I have so far:
// Trial.java
import java.io.*;
import java.util.Arrays;
import java.util.ArrayList;
import ...