Skip to main content

Posts

Showing posts with the label string

When to use strtr vs str_replace?

I'm having a hard time understanding when strtr would be preferable to str_replace or vice versa. It seems that it's possible to achieve the exact same results using either function, although the order in which substrings are replaced is reversed. For example:

What is the difference between " and " in JavaScript?

I saw this question and I am wondering about the same thing in JavaScript. If you use the character ' or the character " when making strings in JavaScript, the application seems to behave the same. So what is the difference between these two characters? The only advantage I have seen in using ' to build strings is that I can do stuff like: var toAppend = '<div id="myDiv1"></div>'; Instead of: var toAppend = "<div id=\"myDiv1\"></div>"; Is there any significant difference between them that I should be aware of? Source: Tips4all

PHP: Truncate HTML, ignoring tags

I want to truncate some text (loaded from a database or text file), but it contains HTML so as a result the tags are included and less text will be returned. This can then result in tags not being closed, or being partially closed (so Tidy may not work properly and there is still less content). How can I truncate based on the text (and probably stopping when you get to a table as that could cause more complex issues). substr("Hello, my <strong>name</strong> is <em>Sam</em>. I&acute;m a web developer.",0,26)."..." Would result in: Hello, my <strong>name</st... What I would want is: Hello, my <strong>name</strong> is <em>Sam</em>. I&acute;m... How can I do this? While my question is for how to do it in PHP, it would be good to know how to do it in C#... either should be OK as I think I would be able to port the method over (unless it is a built in method). Also note that I have included an HT

Objective C parse hex string to integer

I would like to know how to parse a hex string, representing a number, in objective c. I am willing to use both an objective, or a C based method, either is fine. example: #01FFFFAB should parse into the integer: 33554347 Any help would be appreciated!

Convert String to Int Objective-C?

Really basic iPhone Objective-C question. I'm trying to extract a string (which is really a int) from an array and then use it as an int in a function. I'm trying to convert it to a int using intValue. Here's the code I've been trying. NSArray *_returnedArguments = [serverOutput componentsSeparatedByString:@":"]; [_appDelegate loggedIn:usernameField.text:passwordField.text:(int)[[_returnedArguments objectAtIndex:2] intValue]]; I get the error passing argument 3 of 'loggedIn:::' makes pointer from integer without a cast Thanks for the help, Christian Stewart

Is it good practice to use java.lang.String.intern()?

The Javadoc about String.intern() doesn't give much detail. (In a nutshell: It returns a canonical representation of the string, allowing interned strings to be compared using == ) When would I use this function in favor to String.equals() ? Are there side effects not mentioned in the Javadoc, i.e. more or less optimization by the JIT compiler? Are there further uses of String.intern() ?

Android JAVA String Validation

i have a question : I want to create an app that take a String from user input. This String will be in an email format. So there's some requirement's : .(full stop) can't be placed before @ .(full stop) and @ can't be more than one .(full stop) and @ can't be side by side Note : This is NOT a school homework(i just felt that this is like a homework after i typed it), i just want to learn more about String :D I already did some research's but i still can't solve those problem's :D Thanks all, and sory if i made some mistake's, English is not my native languange :D

Convert String to Long

Is it possible to convert a String to long without using java's built in function? For instance: String s = "35"; long ans = Long.parseLong(s); How can you carry out the same task without using java's Long.parseLong function

Want to convert a string in one form into another form in JAVA?

I have a string like "isnull(col_name,0)<>1 or isnull(col1_name,0)=0 and isnull(col2_name,0)>=100... " I want to convert above string in below form as: " (col_name is null or col_name<>1) or (col1_name is null or col1_name=0) and (col2_name is null or col2_name>=100) ... " I want to implement this in JAVA. I have tried with using split function but the case is not the similar everytime(means is between two there may be 'OR' or 'AND', so how to split?). Then I tried with contains function but how to replace that complete part of isnull in required form. (I have also tried with using character array,it works somewhat fine but fails somewhere according to my code.) Actually I tried a lot with different ways but I am not able to build the good logic which will work fast. Pls suggest me some good idea for this. Sorry for my bad english. Thanks.

Convert android.graphics.path value into String?

I have an ArrayList of Path values. I need to convert it into String values and know what all coordinates were covered in the Path. Here's the code that I worked up: private ArrayList<Path> pointsToDraw = new ArrayList<Path>(); private List<String> stringPoints ; synchronized(pointsToDraw){ for(Path path : pointsToDraw) { stringPoints.add(String.valueOf(path)); } TextView b1Text = (TextView) findViewById(R.id.GText); for(String s : stringPoints) { b1Text.setText(s); } } I get an exception during runtime. The following is the log content : 02-21 18:18:29.323: E/AndroidRuntime(512): FATAL EXCEPTION: main 02-21 18:18:29.323: E/AndroidRuntime(512): java.lang.NullPointerException 02-21 18:18:29.323: E/AndroidRuntime(512): at learn.myandroidapp.hr.HRCanvas$1.on