string

Truncate a string with an ellipsis, making sure not to break any HTML entity

I have a database of items with XHTML content and I want to display the items with the HTML stripped off (done) and then truncate each item to a maximum length of 100 characters. If the string exceeds 100 characters, I cut it off and insert … (an ellipsis) at the end. The problem is that my program doesn't understand HTML entitie...

ruby 1.9: how do I get a byte-index-based slice of a String?

I'm working with UTF-8 strings. I need to get a slice using byte-based indexes, not char-based. I found references on the web to String#subseq, which is supposed to be like String#[], but for bytes. Alas, it seems not to have made it to 1.9.1. Now, why would I want to do that? There's a chance I'll end up with an invalid string should ...

Can one initialise a java String with a single repeated character to a specific length.

I'd like to create a function that has the following signature: public String createString(int length, char ch) It should return a string of repeating characters of the specified length. For example if length is 5 and ch is 'p' the return value should be ppppp Is there a way to do this without looping until it is the required ...

How do you convert from a nsACString to a LPCWSTR?

I'm making a firefox extension (nsACString is from mozilla) but LoadLibrary expects a LPCWSTR. I googled a few options but nothing worked. Sort of out of my depth with strings so any references would also be appreciated. ...

Is there an easy way to compare two strings in a jsp?

I am creating a drop down list of all languages, with the language used when creating other info in the page as the default selected in the list: <select> <c:forEach items="${languages}" var="lang"> <c:choose> <c:when test="${lang}.equals(${pageLang})"> <option value="${lang}" selected>${lang}</option> </c:whe...

valgrind report memory leak when assign a value to a string

Valgrind report memory leak when assign a value to a string I used this simple code to test an memory leak reported by valgrind. /****************************************** * FILE: t3.c * Compiled using : g++ -g t3.c -o t3 * * $ g++ -v * Reading specs from /usr/lib/gcc/i686-pc-linux-gnu/3.4.6/specs * Configured with: ./configure --pre...

Does the String pool take local variables?

I believed the String pool abandoned local Strings when their methods completed Yet: public class TestPool implements Runnable{ /** * @param args the command line arguments */ public void run() { String str= "hello"; synchronized(str){ try { System.out.print(Thread.current...

String problem in PHP

How do I take off a certain character in a string and put them all together in an array like: "{2} in better that {1} when it comes to blah blah blah" and the output would be: array(0 => "2", 1 => "1"); I have used regular expression but it seems like it doesn't loop throughout the string or maybe I'm missing something? Thanks ...

Prefix search through list/dictionary using .NET StringDictionary?

I was wondering if .NET offers any standard functionality for doing a prefix search through a list or a dictionary object. I came across the StringDictionary, but couldn't figure out if it can do that for me. And if it can do a prefix search, can it also do substring search or let me search using something like a regular expression? Th...

C# Decimal Formatting Query

I am trying to format a decimal so that it will get displayed as so: 14.5 should get displayed as "14.50" 14.50 should get displayed as "14.50" 14.05 should get displayed as "14.05" 14.00 should get displayed as "14" Is the possible with a single String Format, i.e. not using conditional formatting? I've tried "0.##" (doesn't satisfy ...

Java Strings and StringPool

public String makinStrings() { String m = "Fred47"; String s = "Fred"; s = s + "47"; s = s.substring(0); return s.toString(); } How many objects are created by the code? I made a simple test: public static void main(String[] args) { String m = "a"; m += "bc"; String s1 = "mabc".substring(1); String s2 = "ab...

Extract Integer Part in String

What is the best way to extract the integer part of a string like Hello123 How do you get the 123 part. You can sort of hack it using Java's Scanner, is there a better way? ...

DateTime question

Hi, I have 2 DateTime objects, which I save to a file after using the ToShortDateString() function; the strings look like "12/15/2009". I am stuck on this part now, I want to initialize DateTimeObject(s) with these strings so I can compare the timespan between the date dates. Any help appreciated. ...

Convert single-quoted string to double

I want to check whether the given string is single- or double-quoted. If it is single quote I want to convert it to be double quote, else it has to be same double quote. ...

How do I concatenate html as a string in VBA?

I'm a newbie at VBA and html and I'm getting very confused. I'm trying to set a string variable to equal several concatenated html strings and control values. I can't figure out what I'm doing wrong. Here is my code: htmlText = "<HTML><BODY bgcolor=#0b3767> <img height=""71"" width=""500"" alt=""Central Analysis Bureau, Inc. - Kno...

MySQL Using a string column with date text as a date field

I am doing a database migration and I currently have a string column with dates (versus having the optimal datetime field set for these). Is there a function I can call in MySQL to convert this field to a datetime so I can use the date features such as before this date or after this date? ...

Dynamically add a field to a collection in c#?

I have some basic dropdownlist databinding code. I need to modify the datasource at Runtime and insert a new field. ddlPrimaryCarrier.DataSource = FinancialInstitutions; ddlPrimaryCarrier.DataValueField = "EntityCode"; ddlPrimaryCarrier.DataTextField = "EntityNameDesc"; ddlPrimaryCarrier.DataBind()...

get value in jquery

i have one function which return value in this format li#2.ui-widget-content li#6.ui-widget-content li#12.ui-widget-content li#1.ui-widget-content each time i run function i get random value in the above format. i want to get value after li# in jquery Thanks ...

CR character in gets() function

The user types a string, possibly separated by tabs, spaces and "enters" (CRs). I need to receive all of it; the problem is that gets() function stops the scan when the user presses the "Enter" key. Is there another way to do it? I cannot use any other function except for scanf and gets. ...

Check String whether it contains only Latin characters?

Greetings, I am developing GWT application where user can enter his details in Japanese. But the 'userid' and 'password' should only contain English characters(Latin Alphabet). How to validate Strings for this? ...