string

String padding problem

Hi, Using the code given below the padding doesn't seem to be playing as it should, in theory the text "ADD this text" should start from column 21 in both the strings but in str2 it has a few extra spaces. On checking the length of both the strings the length turned out to be the same 20 as expected. string str1 = "Test"...

Inverting a string in Python

I was looking for a way to print a string backwards, and after a quick search on google, I found this method: Suppose 'a' is a string variable. This will return the 'a' string backwards: a[::-1] Can anyone explain how that works? ...

Java String.equals versus ==

This code separates a string into tokens and stores them in an array of strings, and then compares a variable with the first home ... why isn't it working? public static void main (String... aArguments) throws IOException { String usuario = "Jorman"; String password = "14988611"; String strDatos="Jorman 14988611"; StringTokenizer toke...

Occurences of substring in a string

Why is the following algorithm not halting for me? (str is the string I am searching in, findStr is the string I am trying to find) String str = "helloslkhellodjladfjhello"; String findStr = "hello"; int lastIndex = 0; int count =0; while(lastIndex != -1){ lastIndex = str.indexOf(findStr,lastIndex); ...

Finding multiple indexes from source string

Hello, Basically I need to do String.IndexOf() and I need to get array of indexes from the source string. Is there easy way to get array of indexes? Before asking this question I have Googled a lot, but have not found easy solution to solve this simple problem. ...

Split a string in actionscript?

How do I accomplish this in actionscript (example in c#): string[] arr = { "1.a", "2.b", "3.d", "4.d", "5.d" }; int countD = 0; for (int i = 0; i < arr.Length; i++) { if (arr[i].Contains("d")) countD++; } I need to count a character in an array of strings ...

Escaping Strings in JavaScript

Hello, Does JavaScript have a built-in function like PHP's addslashes (or addcslashes) function to add backslashes to characters that need escaping in a string? For example, this: This is a demo string with 'single-quotes' and "double-quotes". ...would become: This is a demo string with \'single-quotes\' and \"double-qu...

What is the difference between .Equals and ==

What is the difference between a.Equals(b) and a == b for value types, reference types, and strings? It would seem as though a == b works just fine for strings, but I'm trying to be sure to use good coding practices. ...

Inserting a Java string in another string without concatenation?

Is there a more elegant way of doing this in Java? String value1 = "Testing"; String test = "text goes here " + value1 + " more text"; Is it possible to put the variable directly in the string and have its value evaluated? ...

How can I convert TBytes to RawByteString?

What is the best way to convert an array of bytes declared as TBytes to a RawByteString in Delphi 2009? This code actually works, maybe there is a faster way (without loop): function Convert(Bytes: TBytes): RawByteString; var I: Integer; begin SetLength(Result, Length(Bytes)); for I := 0 to ABytes - 1 do ...

How to refactor, fix and optimize this character replacement function in java

While tuning the application, I found this routine that strips XML string of CDATA tags and replaces certain characters with character references so these could be displayed in a HTML page. The routine is less than perfect; it will leave trailing space and will break with StringOutOfBounds exception if there is something wrong with the...

Sql Server String Comparision

Is there any information as to how SQL Server compares strings and handles searching in them (like statments)? I am trying to find out if there is a way to determine how efficient it is to store information as a large string and use sql server to do a bunch of comparisons on rows to determine which match. I know this is potentially goi...

Converting String^ to std::string (basic string) -> Error. How can I fix this?

I try to convert a String^ to basic string...but I get the error after this code. What does it mean and how can I fix it? I need to input basic string into a class constructor. The string^ would not work. System::String^ temp = textBox1->Text; string dummy = System::Convert::ToString(temp); error C2440: 'initializing' : cannot convert...

Parsing CSV file with un-escaped quotation marks and commas in .NET

I was wondering if someone could help me. I have to parse data from a csv file and put this into a db table. An example of the data is as follows: "first field", "second , field", "third " Field " ", "fourth field" As you can see there are quotation marks and commas embedded in the fields. I was using ADO.NET but it had issues with t...

String Concatenation unsafe in C#, need to use StringBuilder?

My question is this: Is string concatenation in C# safe? If string concatenation leads to unexpected errors, and replacing that string concatenation by using StringBuilder causes those errors to disappear, what might that indicate? Background: I am developing a small command line C# application. It takes command line arguments, performs...

How do I replace quotes in XSLT with their HTML entities?

This is related to my previous question -" Manipulate the output of <xsl:apply-templates>". I want to ask about the specific problem I am looking to address. How do I replace quotes in XSLT with their HTML entities. I want to eventually pass it to Javascript variable with special characters escaped. ...

Java generics Pair<String, String> stored in HashMap not retrieving key->value properly

Here's Pair.java import java.lang.*; import java.util.*; public class Pair<TYPEA, TYPEB> implements Comparable< Pair<TYPEA, TYPEB> > { protected final TYPEA Key_; protected final TYPEB Value_; public Pair(TYPEA key, TYPEB value) { Key_ = key; Value_ = value; } public TYPEA getKey() { return Key_; } public...

Easy way to Search a string for strings

Exact Duplicate C# Is String in Array Im trying to find the easiest way to search a string for an array of possible strings. I know the easy way to do this for characters is to use myString.IndexOfAny(charArray). But how what if Id like to search my string for strings and not just characters? Are there any .net tricks or methods...

Reversing a string in C

I have developed a reverse-string program. I am wondering if there is a better way to do this, and if my code has any potential problems. I am looking to practice some advanced features of C. char* reverse_string(char *str) { char temp; size_t len = strlen(str) - 1; size_t i; size_t k = len; for(i = 0; i < len; i++) { temp = str[k]; ...

Consistency of hashCode() on a Java string

The hashCode value of a Java String is computed as (String.hashCode()): s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1] Are there any circumstances (say JVM version, vendor, etc.) under which the following expression will evaluate to false? boolean expression = "This is a Java string".hashCode() == 586653468 Update #1: If you claim th...