string

Removing diacritics in Silverlight (String.Normalize issue)

I did create a function that transforms diacritic characters into non-diacritic characters (based on this post) Here’s the code: Public Function RemoveDiacritics(ByVal searchInString As String) As String Dim returnValue As String = "" Dim formD As String = searchInString.Normalize(System.Text.NormalizationForm.FormD) Dim u...

Cleaning and stripping of strings/HTML - Python

Hi folks, I have a set of questions, of which I do not have an answer to. 1) Stripping lists of string input: 'item1, item2, \t\t\t item3, \n\n\n \t, item4, , , item5, ' output: ['item1', 'item2', 'item3', 'item4', 'item5'] Anything more efficient than doing the following? [x.strip() for x in l.split(',') if x.strip()] 2) Clea...

How do I convert an object to a custom string in javascript?

I want to overload the conversion of an object to a string, so that the following example would output the string "TEST" instead of "[object Object]". How do I do this? function TestObj() { this.sValue = "TEST"; } function Test() { var x = new TestObj(); document.write(x); } ...

Python - A Question on String Editing

Hello, I am trying to make a simple text-based game in Python. The idea of which revolves around a deck of playing cards, representing the card face values with A,2,3,4,5,6,7,8,9,10,J,Q, and K (Joker is not used). The suit of the cards will be represented by s,d,h, and c. As an example, "Ace of Hearts" would be represented as Ah. I am ...

Exact string replacement in php

Hi, I'm looking for a way to replace a string in php that exactly matches with the subject. For example I got a file named 'hello-world.txt' having three lines: 'http://www.example.com/' 'http://www.example.com/category/' 'http://www.example.com/tag/name/' and I need to replace the 'http://www.example.com/' with 'http://www.example2....

Can't find string terminator "str" anywhere before EOF

Why I get this error? use strict; use warnings; my $str = <<str; 88087 23/11/2010 35192 25/07/2010 B3J 5X9 17/08/2011 C8U 5L6 16/08/2011 F4Q 3B4 17/10/2010 D3X 9P4 11/05/2010 O7L 6Z8 28/02/2010 W8L 9P2 05/09/2010 str print $str; my @arr = split/\n/,$str; foreach (@arr) { my @tmp = split/\t/; print "$tmp[...

Designing a simple state machine generator

I know that designing state machine generators for regular expressions is not trivial, but what about simple strings (when I say a simple string, I mean something like "abcd" -- something without any regular expression syntax). I was thinking of writing a simple string matcher using state machines, but I wanted the state machine to be ge...

How to obtain the last path segment of an uri

I have in input a string that is an uri how is possible to get the last path segment? that in my case is an id? this is my input url String uri = "http://base_path/some_segment/id" and i have to obtain the id i' have tried with this String strId = "http://base_path/some_segment/id"; strId=strId.replace(path); strId...

Java replaceAll() & split() irregularities

I know, I know, now I have two problems 'n all that, but regex here means I don't have to write two complicated loops. Instead, I have a regex that only I understand, and I'll be employed for yonks. I have a string, say stack.overflow.questions[0].answer[1].postDate, and I need to get the [0] and the [1], preferably in an array. "Easy...

Rhino: How to return a string from java to javascript?

enter code hereHow do I use Rhino return a string from java to javascript, all I get is org.mozilla.javascript.JavaNativeObject when I use var jsString = new java.lang.String("test"); inside my js file. Is this the right way to do it? var jsString = String(new java.lang.String("test")); PS. The goal is to have a java method to ret...

R: Call matrixes from a vector of string names ??

Hello Imagine I've got 100 numeric matrixes with 5 columns each. I keep the names of that matrixes in a vector or list: Mat <- c("GON1EU", "GON2EU", "GON3EU", "NEW4", ....) I also have a vector of coefficients "coef", coef <- c(1, 2, 2, 1, ...) And I want to calculate a resulting vector in this way: coef[1]*GON1EU[,1]+coef[2]*GON...

Better String formatting in Scala

With too many arguments, String.format easily gets too confusing. Is there a more powerful way to format a String. Like so: "This is #{number} string".format("number" -> 1) Or is this not possible because of type issues (format would need to take a Map[String, Any], I assume; don’t know if this would make things worse). Or is the bet...

JavaScript access string chars as array

Hello! Is it ok to do this: var myString="Hello!"; alert(myString[0]); // shows "H" in an alert window Or should it be done with either charAt(0) or substr(0,1)? By "is it ok" I mean will it work on most browsers, is there a best practice recommandation that says otherwise etc. Thank you. ...

Unicode and std::string in C++

If I write a random string to file in C++ consisting of some unicode characters, I am told by my text editor that I have not created a valid UTF-8 file. // Code example const std::string charset = "abcdefgàèíüŷÀ"; file << random_string(charset); // using std::fstream What can I do to solve this? Do I have to do lots of additional manu...

How to format a java string with leading zero?

Here is the String, for example: "Apple", and I would like to add zero to fill in 8 chars. I would like to show the result like this;' "000Apple" How can I do so? Thank you. ...

Most efficient way to make the first character of a String lower case?

Given an input String, what is the most efficient way to make just the first character lower case? I can think of a number of ways to do this. For example, using charAt and subString: String string= "SomeInputString"; string = Character.toLowerCase( string.charAt(0)) + (string.length() > 1 ? string.substring(1) : ""); Or using a ch...

What's the name of this algorithm/routine?

I am writing a utility class which converts strings from one alphabet to another, this is useful in situations where you have a target alphabet you wish to use, with a restriction on the number of characters available. For example, if you can use lower case letters and numbers, but only 12 characters its possible to compress a timestamp...

How to detect a delimiter in a string in PHP?

I am curious if you have a string how would you detect the delimiter? We know php can split a string up with explode() which requires a delimiter parameter. But what about a method to detect the delimiter before sending it to explode function? Right now I am just outputting the string to the user and they enter the delimiter. That's ...

sizeof for a null terminated const char*

const char* a; how do I make sure that string 'a' is null terminated? when a = "abcd" and I do sizeof(a), I get 4. Does that mean its not null-terminated? if it were, I would have gotten 5 ? ...

How to enumerate Linq results?

Referring to this topic: http://stackoverflow.com/questions/4038836/minimize-linq-string-token-counter And using the following provided code: string src = "for each character in the string, take the rest of the " + "string starting from that character " + "as a substring; count it if it starts with the target s...