string

Javascript multiple replace

How do you replace all instances of one string with another in javascript? Example: someString = 'the cat looks like a cat' anotherString = someString.replace('cat', 'dog'); results in anotherString being set to 'the dog looks like a cat', and I would like it to be 'the dog looks like a dog' ...

How can I extract a bunch of numbers from a string?

Hi. This is the sample test file: Barcode:*99899801000689811* JSC4000I accountNumber:10006898Sequence Number:998 Envelopes: 1 LCD5010V Using jsl 'CUSOFF' for output page '6' Barcode:*99999901000673703* LCD5010V Using jsl 'CUSOFF' for output page '4' LCD5005V Using job 'A' for current page '4' So, in this file, how to s...

PHP startsWith() and endsWith() functions

I need two functions that would take a string and return if it starts with the specified character/string or ends with it. For example: $str='|apples}'; echo startsWith($str,'|'); //Returns true echo endsWith($str,'}'); //Returns true ...

PHP ltrim() and rtrim() functions

I need 2 functions that take a string and the number of chars to trim from the right and left side and return it. E.g: $str = "[test]"; $str = ltrim($str,1); //becomes test] $str = rtrim($str,1); //becomes test Thoughts? ...

String or StringBuilder return values?

If I am building a string using a StringBuilder object in a method, would it make sense to: Return the StringBuilder object, and let the calling code call ToString()? return sb; OR Return the string by calling ToString() myself. return sb.ToString(); I guess it make a difference if we're returning small, or large strings. What wo...

SQL: search for a string in every varchar column in a database

I have a database where a misspelled string appears in various places in different tables. Is there a SQL query that I can use to search for this string in every possible varchar/text column in the database? I was thinking of trying to use the information_schema views somehow to create dynamic queries, but I'm not sure if that will wor...

Can a empty java string be created from non-empty UTF-8 byte array?

I'm trying to debug something and I'm wondering if the following code could ever return true public boolean impossible(byte[] myBytes) { if (myBytes.length == 0) return false; String string = new String(myBytes, "UTF-8"); return string.length() == 0; } Is there some value I can pass in that will return true? I've fiddled wit...

How should I convert a number with a text suffix to an integer in c#?

What's the cleanest/best way in C# to convert something like 400AMP or 6M to an integer? I won't always know what the suffix is, and I just want whatever it is to go away and leave me with the number. ...

VARCHAR collation versus VARBINARY ordering in SQL Server 2000

I need to do some in-memory merging in C# of two sorted streams of strings coming from one or more SQL Server 2000 databases into a single sorted stream. These streams of data can be huge, so I don't want to pull both streams into memory. Instead, I need to keep one item at a time from each stream in memory and at each step, compare the ...

C++ STL's String eqivalent for Binary Data

I am writing a C++ application and I was wondering what the C++ conventional way of storing a byte array in memory. Is there something like a string, except specifically made for binary data. Right now I am using a *unsigned char** array to store the data, but something more STL/C++ like would be better. ...

How can I get a java.io.InputStream from a java.lang.String?

I have a String that I want to use as an InputStream. In Java 1.0, you could use java.io.StringBufferInputStream, but that has been @Deprecrated (with good reason--you cannot specify the character set encoding): This class does not properly convert characters into bytes. As of JDK 1.1, the preferred way to create a stream from ...

Force string download with http-header

Hi, I'm having a problem with my function. The purpose of my function is to force a string to be downloaded. What it really happens is that the string is outputted to the screen and not downloaded. This is my function: function arrayToCSV($vectorDados, $cabecalho) { $arr = array(); $arr=$vectorDados; $csv = $cabecalho . "\...

Why do I get a decimal point in my BigInt numbers?

Adding 15 digit numbers like 999999999999990 in Perl produces results with a period such as 1.9999999999999e+. When using substr it still produces 1.99999999999, and when using BigInt the result still has a period. What is the correct Perl syntax for Perl 5.8.7 to get the result without the period? use BigInt; $acct_hash = substr(($acct...

Stripping everything but alphanumeric chars from a string in PHP

I'd like a regexp or other string which can replace everything except alphanumeric chars (a-z and 0-9) from a string. All things such as ,@#$(@*810 should be stripped. Any ideas? Edit: I now need this to strip everything but allow dots, so everything but a-z, 1-9, .. Ideas? ...

What is a quick way to force CRLF in C# / .NET?

How would you normalize all new-line sequences in a string to one type? I'm looking to make them all CRLF for the purpose of email (MIME documents). Ideally this would be wrapped in a static method, executing very quickly, and not using regular expressions (since the variances of line breaks, carriage returns, etc. are limited). Perha...

Why do my Perl bigints have a decimal place?

If I do use a big integer in substr: use BigInt; $acct_hash = substr(('99999999999912345' + $data[1]),0,15); why is the result still 9.9999999999912? I was expecting 999999999999912. Is there something like: $data[1] = substr(to_char('999999999999991234'),0,15); in Perl? ...

How to get the token type from a CFStringTokenizer in Cocoa?

The CFStringTokenizer documentation has two conflicting statements in CFStringTokenizerAdvanceToNextToken(): CFStringTokenizerAdvanceToNextToken ... Return Value The type of the token if the tokenizer succeeded in finding a token and setting it as current token. Returns kCFStringTokenizerTokenNone if the tokenizer fail...

Static Constants in C#

I have this code; using System; namespace Rapido { class Constants { public static const string FrameworkName = "Rapido Framework"; } } Visual Studio tells me: The constant 'Rapido.Constants.FrameworkName' cannot be marked static How can I make this constant available from other classes without having to create...

What's the most efficient way to find one of several substrings in Python?

Hello, I have a list of possible substrings, e.g. ['cat', 'fish', 'dog']. In practice the list contains hundreds of entries. I'm processing a string, and what I'm looking for is to find the index of first appearance of any of these substrings. To clarify, for '012cat' the result is 3, and for '0123dog789cat' the result is 4. I also...

Convert string to CLLocationCoordinate2D

Hi all, I have an array with NSString's in it. Some of these are latitude and longitudes and I need to use this with the below code. The latText and lonText are my strings that I am trying to use as co-ordinates.... CLLocationCoordinate2D pinlocation=mapView.userLocation.coordinate; pinlocation.latitude = latText; pinlocation...