string-manipulation

How to get a desired substring form a String in java or jsf?

Hi, I am developing an application using JSF in Eclipse IDE with Derby as database. I have a feature to upload files to the database. But the file name is getting stored as "C:\Documents and Settings\Angeline\Desktop\test.txt" instead of "test.txt". How do I get to store only "test.txt" as file name in the database? This is my code in J...

ereg_replace missing square brackets?

Hey I have the following code that should strip all non alphanumerics (excluding hyphens) from some text. It does however miss square brackets somehow? ereg_replace('[^A-z0-9-]', '', strtolower(str_replace(' ','-',$title))) Can anyone advise? ...

In Perl, what is the sane way for converting a string into a list of its characters?

I have been wondering if there's a nicer, but concise way for splitting a string into its characters @characters = split //, $string is not that hard to read, but somehow the use of a regular expression looks like overkill to me. I have come up with this: @characters = map { substr $string, $_, 1 } 0 .. length($string) - 1 but I f...

Does Java's toLowerCase() preserve original string length?

Assume two Java String objects String str = "<my string>"; String strLower = str.toLowerCase(); Is it then true that for every value of <my string> str.length() == strLower.length() evaluates to true? So, does String.toLowerCase() preserve original string length for any value of String? ...

Inline code block within asp:Image

I'm trying to do a String.Replace inside my asp:image tag (nested in a Repeater) in order to change an apostrophe to an html friendly apostrophe <asp:Image ID="Image1" runat="server" ImageUrl='<%# String.Format("~/images/products/{0}", XPath("image"))%>' Visible='<%# CheckEmpty(XPath("image")) %>' ...

question with returning an accessor method

How would I get the accessor method to return the first letter of a name to be uppercase and the rest in lowercase no matter what was entered? public class Name { private String first; private String last; /** * Constructor for objects of class Name */ public Name(String firstName, String lastName) { ...

Output '{' or '}' with string.format(...)

I bet that's an easy question for you, but searching SO or Google with { or } in the search string doesn't work very well. So, let's say i wanna output {Hello World}, how do i do this using string.format(...)? Edit: looks like this: string hello = "Hello World"; string.format("{0}", '{' + hello + '}'); would do the job, but that do...

Regarding double dataype

I have a double variable test. I want to extract the all digits before decimal point and two digits after the decimal point store the output in integer variables dollar, cents. how can i do it? I dont want any rounding to happen. example: double test= 12.1234 Output int dollar =12; int cents =12; double test =1235.0 output int ...

Assigning String.Empty plus some string to a button text

I stumbled upon this code and I am curious as to what use may the string.Empty part have in it. Is it as completely useless as it seems? Am I missing something? System.Windows.Forms.ToolStripButton m_button; int errorCount; ... m_button.Text = string.Empty + errorCount + " error(s)"; ...

Why doesn't Đ get flatten to D when Removing Accents/Diacritics

I'm using this method to remove accents from my strings: static string RemoveAccents(string input) { string normalized = input.Normalize(NormalizationForm.FormKD); StringBuilder builder = new StringBuilder(); foreach (char c in normalized) { if (char.GetUnicodeCategory(c) != UnicodeCategory.NonSpacingMark...

Runtime error in StringBuilder instance

Please, help me understand, what's wrong with this code. (I am trying to build a string, taking parts of it line by line from a text file). I get a runtime error "In the instance of the object reference not set to an object" on the line strbuild.Append(str); StreamReader reader = new StreamReader("buf.txt", System.Text.Encodin...

Perl substitution using string that contains a dollar sign on windows

I'm using perl on windows and am trying to do a one liner using perl to substitute a placeholder in a file using a windows variable that contains a dollar sign. Does anyone know what the correct usage is to make it work with the dollar sign. I've tried various ways and can't seem to get it to work. For example, I have a properties file...

python file manipulation

I have a file with entries such as: 26 1 33 2 . . . and another file with sentences in english I have to write a script to print the 1st word in sentence number 26 and the 2nd word in sentence 33. How do I do it? ...

find the position of a string in another string

Possible Duplicate: substring algorithm Given two strings, A and B, how to find the first position of B in A? For instance, A = " ab123cdefgcde"; B= "cde" Then the first position of B in A is 5. Is there any trick to solve this problem or just search A from the start? ...

Convert array to comma-delimited text

Apologies for this embarassingly simple question but I'm still relatively new to javascript. I have an array of names, something like var myArray = ['Hill M','Zhang F','Dong L', 'Wilkinson JS', 'Harris N']; I would like to return a string, with names separated by commas, but with "and" between the final two names, i.e. 'Hill M, Zhan...

php, second last comma in a string to break string, or regex

I'm trying to find a way to break a string at the second last comma, for example: piece 1, piece 2, piece 3, piece 4, piece 5, piece 6, piece 7 should be 2 parts: piece 1, piece 2, piece 3, piece 4, piece 5 and piece 6, piece 7 and piece 1, piece 2, piece 3, piece 4, piece 5 should be: piece 1, piece 2, piece 3 and piece 4, piec...

Need to convert an ISBN value into an Amazon search query link using XSLT

I am using XSL to transform a resource attribute, it will check whether or not it contains "urn:ISBN". If it does, then it will need to get the ISBN number value, and return it as an Amazon search query. For example resource="urn:ISBN:0752820907" then change into http://www.amazon.com/gp/search/ref=sr_adv_b/?field-isbn=0752820907 ...

Converting to upper and lower case in Java

I want to convert the first character of a string to Uppercase and the rest of the characters to lowercase. How can I do it? Example: String inputval="ABCb" OR "a123BC_DET" or "aBcd" String outputval="Abcb" or "A123bc_det" or "Abcd" ...

how to achieve timespan to string conversion??

I tried searching here, but it couldn't help me much .. I want to convert time_span to string, I don't want to return the timespan in days .. but only HH:mm:ss. How to achieve that? My sample code is here: String time_span_par = "06:12:40"; String time_str = "18:13:59"; TimeSpan time_span_var...

case insensitive string search csharp

Hi There, What is the quickest most efficient way to search text for words using non-casesensitive search. E.g here is my text to be searched : string textTosearch = "Here is a paragraph or Some text. Here is some more text". If i wanted to find the indexes of "Some" and "some", is there a .Net class string that does this or would i nee...