Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options answers only not deleted user 7076

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.

5 votes
Accepted

Coderbyte: String Reduction

A few minor notes: Have the function StringReduction(str) strictly speaking, the parameter name is different: function StringReduction(s) :-) var original, key; I'd put the va …
palacsint's user avatar
  • 29.9k
5 votes
Accepted

Slug URL Generator

You could create a few explanatory local variables: $lettersNumbersSpacesHypens = '/[^\-\sa-zA-Z0-9]+/'; $spacesAndDuplicateHyphens = '/[\-\s]+/'; Usage: $lettersNumbersSpacesHypens = '/[^\-\sa-z …
palacsint's user avatar
  • 29.9k
11 votes
Accepted

Converting a numerical string to the equivalent multipled by 100

It would be much easier with BigDecimals: String input = "00007.880000"; BigDecimal hundred = BigDecimal.valueOf(100); BigDecimal result = new BigDecimal(input).multiply(hundred).stripTrailingZeros( …
palacsint's user avatar
  • 29.9k
9 votes

Count number of each char in a String

Actually, there is an even better structure than maps and arrays for this kind of counting: Multisets. Documentation of Google Guava mentions a very similar case: The traditional Java idiom for e …
palacsint's user avatar
  • 29.9k
0 votes

Find and replace String with a substring result

The second version looks fine. Anyway, two other quick ideas: Consider replacing only complete words (substrings which has whitespace before and after). Sort the term list by length (descending) and …
palacsint's user avatar
  • 29.9k
2 votes

Pattern Matching with Mismatch

It looks fine. Some readability improvements: I'd rename some variables first: mismatches should be tolerance, mismatchTolerance or allowedMismatches. For me mismatches sounds like a counter but i …
palacsint's user avatar
  • 29.9k
3 votes
Accepted

How to re-factor a common String comparison

It seems data envy. I'd create nameContains method in the Manager class. public boolean nameContains(final String searchText) { if (StringUtils.contains(name, searchText)) { return true; …
palacsint's user avatar
  • 29.9k
17 votes
Accepted

Better way to manipulate this string in sequence?

You could create a StringProcessor interface: public interface StringProcessor { String process(String input); } public class BoldProcessor implements StringProcessor { public String proc …
palacsint's user avatar
  • 29.9k
6 votes

Removing everything after a certain character

You're using the same variable for two different purpose. It would be readable with separate variables: $urlWithoutParameters = strstr($url, "?", true); if ($urlWithoutParameters !== FALSE) { // …
palacsint's user avatar
  • 29.9k
17 votes

Reverse a String in Java

Learn from the existing implementations, they usually have solutions to corner cases and common pitfalls. For example, Apache Commons Lang StringUtils also has a reverse function. Its implementation i …
palacsint's user avatar
  • 29.9k
6 votes

Reverse word by word efficiency

Ideas I had in mind were simply using char[] instead of strings being that strings are immutable and each time I concatenate the Strings, I am creating a new String object which is not efficient at … Go ahead and write it :-) Instead of Strings like strResult and strBuffer you could use StringBuilders (although using char is probably faster). …
palacsint's user avatar
  • 29.9k
4 votes

Poke-a-Dot (Provider)

Another idea is storing an array of strings in the ThreadLocal and extending the array on demand if the required lenght is longer than paddings.lenght: String paddings[] = new String[max]; for (int i …
palacsint's user avatar
  • 29.9k
6 votes

Random string generation

Some general idea, I hope all work in C# too. Feel free to edit the answer if it is not a proper C# syntax. 1, Change the type of the characters list to char and change the loop variable to char too. …
palacsint's user avatar
  • 29.9k
4 votes

Review on code for duplicate removal

According to the Code Conventions for the Java Programming Language if statements always use braces {}. It's error-prone, so change if(chars == null) return null; to if (chars == null) …
palacsint's user avatar
  • 29.9k
4 votes

Finding the most frequent character in a string

I agree with @Mike Nakis, plus: 1, The first loop could be changed to int holder[26] = {0}; How to initialize an array in C 2, The second loop doesn't check that bytes[i] - 97 is lower than 0 or …
palacsint's user avatar
  • 29.9k

15 30 50 per page