Search Results

Search found 37183 results on 1488 pages for 'string conversion'.

Page 12/1488 | < Previous Page | 8 9 10 11 12 13 14 15 16 17 18 19  | Next Page >

  • How to decoding the string in iphone

    - by Pugal Devan
    Hi, I want to decode my string. I have used parsing and get a string from RSS feed. In a string these special characters are not allowed &,<, in my app. So server side encoding those characters and give it to the string. So now i got the string like, Actual String : <Tom&Jerry> (only these characters are not allowed in node data & < >). After Encoding: %3CTom%26Jerry%3E. But i need to display the string is <Tom&Jerry> So how can i decode the string. Please help me out. Thanks.

    Read the article

  • How to replace characters in a java String?

    - by ManBugra
    I like to replace a certain set of characters of a string with a corresponding replacement character in an efficent way. For example: String sourceCharacters = "šdccŠÐCCžŽ"; String targetCharacters = "sdccSDCCzZ"; String result = replaceChars("Gracišce", sourceCharacters , targetCharacters ); Assert.equals(result,"Gracisce") == true; Is there are more efficient way than to use the replaceAll method of the String class? My first idea was: final String s = "Gracišce"; String sourceCharacters = "šdccŠÐCCžŽ"; String targetCharacters = "sdccSDCCzZ"; // preparation final char[] sourceString = s.toCharArray(); final char result[] = new char[sourceString.length]; final char[] targetCharactersArray = targetCharacters.toCharArray(); // main work for(int i=0,l=sourceString.length;i<l;++i) { final int pos = sourceCharacters.indexOf(sourceString[i]); result[i] = pos!=-1 ? targetCharactersArray[pos] : sourceString[i]; } // result String resultString = new String(result); Any ideas? Btw, the UTF-8 characters are causing the trouble, with US_ASCII it works fine.

    Read the article

  • String operations

    - by NEO
    I am trying to find the most repeated word in a string. My code is as follows: public class Word { private String toWord; private int Count; public Word(int count, String word){ toWord = word; Count = count; } public static void main(String args[]){ String str="my name is neo and my other name is also neo because I am neo"; String []str1=str.split(" "); Word w1=new Word(0,str1[0]); LinkedList<Word> list = new LinkedList<Word>(); list.add(w1); ListIterator itr = list.listIterator(); for(int i=1;i<str1.length;i++){ while(itr.hasNext()){ if(str1[i].equalsTO(????)); else list.add(new Word(0,str1[i])); } How do I compare the string from string array str1 to the string stored in the linked list and then how do i increase the respective count. I will then print the string with the highest count, I dont know how to do that either.

    Read the article

  • String from Httpresponse not passing full value.

    - by Shekhar_Pro
    HI i am in desperate need for help here, I am making a web request and getting a json string with Response.ContentLenth=2246 but when i parse it in a string it gives only few 100 characters, i traked it down that it is only getting values less than 964. strings length is still 2246 but remaining values are just (\0) null characters. Its also giving an error Unterminated string passed in. (2246): at following line FacebookFeed feed = sr.Deserialize<FacebookFeed>(data); It works fine if the response stream contains characters less than 964 chars. Following is the extract from the full code error encountered in last line. System.Web.Script.Serialization.JavaScriptSerializer sr = new System.Web.Script.Serialization.JavaScriptSerializer(); System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(@"https://graph.facebook.com/100000570310973_181080451920964"); req.Method = "GET"; System.Net.HttpWebResponse res = (System.Net.HttpWebResponse)req.GetResponse(); byte[] resp = new byte[(int)res.ContentLength]; res.GetResponseStream().Read(resp, 0, (int)res.ContentLength); string data = Encoding.UTF8.GetString(resp); FacebookFeed feed = sr.Deserialize<FacebookFeed>(data); error given is Unterminated string passed in. (2246): {"id":"100000570310973_1810804519209........ (with rest of data in the string data including null chars) following is the shape of classes used in my code: public class FacebookFeed { public string id { get; set; } public NameIdPair from { get; set; } public NameIdPair to { get; set; } public string message { get; set; } public Uri link{get;set;} public string name{get; set;} public string caption { get; set; } public Uri icon { get; set; } public NameLinkPair[] actions { get; set; } public string type { get; set; } public NameIdPair application { get; set; } //Mentioned in Graph API as attribution public DateTime created_time { get; set; } public DateTime updated_time { get; set; } public FacebookPostLikes likes { get; set; } } public class NameIdPair { public string name { get; set; } public string id { get; set; } } public class NameLinkPair { public string name { get; set; } public Uri link{get; set;} } public class FacebookPostLikes { public NameIdPair[] data { get; set; } public int count { get; set; } }

    Read the article

  • Write Parcelable for ArrayList<String []> in android?

    - by sugan.s
    I just created model with String array and array list of string array.Like this public class LookUpModel implements Parcelable { private String [] lookup_header; private ArrayList<String []> loookup_values; public void writeToParcel(Parcel dest, int flags) { dest.writeStringArray(getLookup_header()); }; } I have implemented parcelbale then write for String [] but how to do for the ArrayList<String []> and that values need to pass to another activity.Thanks in advance.

    Read the article

  • How to Convert Boolean to String

    - by tag
    I have a boolean variable which I want to convert to a string $res = true; I need it the converted value to also be in the format "true" "false" not "0" "1" $converted_res = "true"; $converted_res = "false"; I've tried: $converted_res = string($res); $converted_res = String($res); but it tells me string and String are not recognized functions. How do I convert this boolean to a string in the format "true" or "false" in php?

    Read the article

  • How to remove characters from a string?

    - by masato-san
    Hi, Below is interview question so you cannot relay on the functions that predefined in libraries. Also my answer below set the element to null but there is another ways to solve the problem. Given string $string = "This is a pen", remove "is" so that return value is "Th a pen" (including whitespece). I've tried (shown below) but returned value is not correct. Thanks in advance! function remove_delimiter_from_string(&$string, $del) { for($i=0; $i<strlen($string); $i++) { for($j=0; $j<strlen($del); $j++) { if($string[$i] == $del[$j]) { $string[$i] = $string[$i+$j]; //this grabs delimiter :( } } } echo $string . "\n"; }

    Read the article

  • How to get N random string from a {a1|a2|a3} format string?

    - by Pentium10
    Take this string as input: string s="planets {Sun|Mercury|Venus|Earth|Mars|Jupiter|Saturn|Uranus|Neptune}" How would I choose randomly N from the set, then join them with comma. The set is defined between {} and options are separated with | pipe. The order is maintained. Some output could be: string output1="planets Sun, Venus"; string output2="planets Neptune"; string output3="planets Earth, Saturn, Uranus, Neptune"; string output4="planets Uranus, Saturn";// bad example, order is not correct Java 1.5

    Read the article

  • Matching String.

    - by Harikrishna
    I have a string String mainString="///BUY/SELL///ORDERTIME///RT///QTY///BROKERAGE///NETRATE///AMOUNTRS///RATE///SCNM///"; Now I have another strings String str1= "RT"; which should be matched only with RT which is substring of string mainString but not with ORDERTIME which is also substring of string mainString. String str2= "RATE" ; And RATE(str2) should be matched with RATE which is substring of string mainString but not with NETRATE which is also substring of string mainString. How can we do that ?

    Read the article

  • how to use same string in two java files

    - by Palike
    Sorry for my bad English and for maybe stupid question but I'm new in Java. I need use same string in 2 java files for example: In first java file I've got code for sending emails, I've got string set to default email: public String mail = new String ("[email protected]"); and I use this string in code for send email: email.addTo(mail); In second java file something like set up where can user set new email address I want to have same string, connected with string in first java file. When user put new email String mail will be change to new email address and in email.addTo(mail); will be use this new address How can I do this?

    Read the article

  • XML Serializing a class with a Dictionary<string, List<string>> object

    - by Matt
    Is it possible to implement IXmlSerializable and in my XML file capture an object of type Dictionary ? I have the following public class coolio : IXmlSerializable { private int a; private bool b; private string c; private Dictionary<string, List<string>> coco; public coolio(int _a, bool _b, string _c, Dictionary<string, List<string>> _coco) { a=_a; b=_b; c=_c; coco=_coco; } public System.Xml.Schema.XmlSchema GetSchema() { return null; } public void WriteXml(XmlWriter writer) { const string myType = "coolio"; writer.WriteStartElement(myType); writer.WriteAttributeString("a", a.ToString()); writer.WriteAttributeString("b", b.ToString()); writer.WriteAttributeString("c", c); // How do I add a subelement for Dictionary<string, List<string>> coco? writer.WriteEndElement(); } public void ReadXml(XmlReader reader) { if (reader.MoveToContent() != XmlNodeType.Element || reader.LocalName != "coolio") return; a= int.Parse(reader["a"]); b = bool.Parse(reader["b"]); c= reader["c"]; // How do I read subelement into Dictionary<string, List<string>> coco? } } But I am stumped as to how I could add the Dictionary (XML seriliazed to my XML file)

    Read the article

  • Avoiding resource (localizable string) duplication with String.Format

    - by Hrvoje Prgeša
    I'm working on a application (.NET, but not relevant) where there is large potential for resource/string duplication - most of these strings are simple like: Volume: 33 Volume: 33 (dB) Volume 33 dB Volume (dB) Command - Volume: 33 (dB) where X, Y and unit are the same. Should I define a new resource for each of the string or is it preferable to use String.Format to simplify some of these, eg.: String.Format("{0}: {1}", Resource.Volume, 33) String.Format("{0}: {1} {2}", Resource.Volume, 33, Resource.dB) Resource.Volume String.Format("{0} ({1})", 33, Resource.dB) String.Format("{0} ({1})", Resource.Volume, Resource.dB) String.Format("Command - {0}: {1} {2}", Resource.Volume, 33, Resource.dB) I would also define string formats like "{0}: {1}" in the resources so there would be a possibility of reordering words... I would not use this approach selectivly and not throughout the whole application.. And how about: String.Format("{0}: {1}", Volume, Resource.Muted_Volume) // = Volume: Muted Resource.Muted_Volume String.Format("{0}: {1} (by user {2})", Volume, Resource.Muted_Volume, "xy") // = Volume: Muted (by user xy) The advantage is cutting the number of resource by the factor of 4-5. Are there any hidden dangers of using this approach? Could someone give me an example (language) where this would not work correctly?

    Read the article

  • Optimizing a lot of Scanner.findWithinHorizon(pattern, 0) calls

    - by darvids0n
    I'm building a process which extracts data from 6 csv-style files and two poorly laid out .txt reports and builds output CSVs, and I'm fully aware that there's going to be some overhead searching through all that whitespace thousands of times, but I never anticipated converting about about 50,000 records would take 12 hours. Excerpt of my manual matching code (I know it's horrible that I use lists of tokens like that, but it was the best thing I could think of): public static String lookup(List<String> tokensBefore, List<String> tokensAfter) { String result = null; while(_match(tokensBefore)) { // block until all input is read if(id.hasNext()) { result = id.next(); // capture the next token that matches if(_matchImmediate(tokensAfter)) // try to match tokensAfter to this result return result; } else return null; // end of file; no match } return null; // no matches } private static boolean _match(List<String> tokens) { return _match(tokens, true); } private static boolean _match(List<String> tokens, boolean block) { if(tokens != null && !tokens.isEmpty()) { if(id.findWithinHorizon(tokens.get(0), 0) == null) return false; for(int i = 1; i <= tokens.size(); i++) { if (i == tokens.size()) { // matches all tokens return true; } else if(id.hasNext() && !id.next().matches(tokens.get(i))) { break; // break to blocking behaviour } } } else { return true; // empty list always matches } if(block) return _match(tokens); // loop until we find something or nothing else return false; // return after just one attempted match } private static boolean _matchImmediate(List<String> tokens) { if(tokens != null) { for(int i = 0; i <= tokens.size(); i++) { if (i == tokens.size()) { // matches all tokens return true; } else if(!id.hasNext() || !id.next().matches(tokens.get(i))) { return false; // doesn't match, or end of file } } return false; // we have some serious problems if this ever gets called } else { return true; // empty list always matches } } Basically wondering how I would work in an efficient string search (Boyer-Moore or similar). My Scanner id is scanning a java.util.String, figured buffering it to memory would reduce I/O since the search here is being performed thousands of times on a relatively small file. The performance increase compared to scanning a BufferedReader(FileReader(File)) was probably less than 1%, the process still looks to be taking a LONG time. I've also traced execution and the slowness of my overall conversion process is definitely between the first and last like of the lookup method. In fact, so much so that I ran a shortcut process to count the number of occurrences of various identifiers in the .csv-style files (I use 2 lookup methods, this is just one of them) and the process completed indexing approx 4 different identifiers for 50,000 records in less than a minute. Compared to 12 hours, that's instant. Some notes (updated): I don't necessarily need the pattern-matching behaviour, I only get the first field of a line of text so I need to match line breaks or use Scanner.nextLine(). All ID numbers I need start at position 0 of a line and run through til the first block of whitespace, after which is the name of the corresponding object. I would ideally want to return a String, not an int locating the line number or start position of the result, but if it's faster then it will still work just fine. If an int is being returned, however, then I would now have to seek to that line again just to get the ID; storing the ID of every line that is searched sounds like a way around that. Anything to help me out, even if it saves 1ms per search, will help, so all input is appreciated. Thankyou! Usage scenario 1: I have a list of objects in file A, who in the old-style system have an id number which is not in file A. It is, however, POSSIBLY in another csv-style file (file B) or possibly still in a .txt report (file C) which each also contain a bunch of other information which is not useful here, and so file B needs to be searched through for the object's full name (1 token since it would reside within the second column of any given line), and then the first column should be the ID number. If that doesn't work, we then have to split the search token by whitespace into separate tokens before doing a search of file C for those tokens as well. Generalised code: String field; for (/* each record in file A */) { /* construct the rest of this object from file A info */ // now to find the ID, if we can List<String> objectName = new ArrayList<String>(1); objectName.add(Pattern.quote(thisObject.fullName)); field = lookup(objectSearchToken, objectName); // search file B if(field == null) // not found in file B { lookupReset(false); // initialise scanner to check file C objectName.clear(); // not using the full name String[] tokens = thisObject.fullName.split(id.delimiter().pattern()); for(String s : tokens) objectName.add(Pattern.quote(s)); field = lookup(objectSearchToken, objectName); // search file C lookupReset(true); // back to file B } else { /* found it, file B specific processing here */ } if(field != null) // found it in B or C thisObject.ID = field; } The objectName tokens are all uppercase words with possible hyphens or apostrophes in them, separated by spaces. Much like a person's name. As per a comment, I will pre-compile the regex for my objectSearchToken, which is just [\r\n]+. What's ending up happening in file C is, every single line is being checked, even the 95% of lines which don't contain an ID number and object name at the start. Would it be quicker to use ^[\r\n]+.*(objectname) instead of two separate regexes? It may reduce the number of _match executions. The more general case of that would be, concatenate all tokensBefore with all tokensAfter, and put a .* in the middle. It would need to be matching backwards through the file though, otherwise it would match the correct line but with a huge .* block in the middle with lots of lines. The above situation could be resolved if I could get java.util.Scanner to return the token previous to the current one after a call to findWithinHorizon. I have another usage scenario. Will put it up asap.

    Read the article

  • Units of measurement conversion logic in C#

    - by EvanRyan
    I am adding a feature to my program in which the user will have the ability to change their unit of measurement at any time, and have the program recalculate their input and output. If the user inputs say, 20lbs for an item, then decides he wants to work in kilograms instead, he can select an option to do so at any time, and the program will recalculate his 20lb input to 9Kg. Then if he decides he'd rather work in ounces, it would convert that 9Kg to 320oz, so on and so forth. What would be the most effective and efficient way to go about this? I've been racking my brain trying to figure out a way to have the correct formula be implemented.

    Read the article

  • Using antlr and the DLR together -- AST conversion

    - by RCIX
    I have an AST generated via ANTLR, and I need to convert it to a DLR-compatible one (Expression Trees). However, it would seem that i can't use tree pattern matchers for this as expression trees need their subtrees at instantiation (which i can't get). What solution would be best for me to use?

    Read the article

  • Implicit conversion : const reference vs non-const reference vs non-reference

    - by Nawaz
    Consider this code, struct A {}; struct B { B(const A&) {} }; void f(B) { cout << "f()"<<endl; } void g(A &a) { cout << "g()" <<endl; f(a); //a is implicitly converted into B. } int main() { A a; g(a); } This compiles fine, runs fine. But if I change f(B) to f(B&), it doesn't compile. If I write f(const B&), it again compiles fine, runs fine. Why is the reason and rationale? Summary: void f(B); //okay void f(B&); //error void f(const B&); //okay I would like to hear reasons, rationale and reference(s) from the language specification, for each of these cases. Of course, the function signatures themselves are not incorrect. Rather A implicitly converts into B and const B&, but not into B&, and that causes the compilation error.

    Read the article

  • Streaming and conversion of video from 3rd Parth

    - by Ashish
    Hi, I am working on a App where video has to be displayed.All these video are in .flv format, Is there any mechanism by using that I can convert this video to .mov or .m4v (supported by iphone) on the fly, so that user can view those video on their iphone or ipod. Thanks, Ashish

    Read the article

  • Perl coding to PHP coding conversion

    - by Haskella
    Hi, I am trying to convert some Perl into PHP using this guideline: http://www.cs.wcupa.edu/~rkline/perl2php/#basedir Basically I know next to nothing about these two languages. Please give me some simple English explanation of what each line does, I'll be more than happy. Thanks for reading :D Perl CGI program: #!/usr/bin/perl -T use strict; use warnings; use CGI (); my %fruit_codes = ( apple => '2321.html', banana => '1234.html', coconut => '8889.html', ); my $c = CGI->new; my $fruit_parameter = $c->param('fruit_name'); my $iframe_document; if (defined $fruit_parameter and exists $fruit_codes{$fruit_parameter}) { $iframe_document = $fruit_codes{$fruit_parameter}; } else { $iframe_document = 'sorry-no-such-fruit.html'; } $c->header('application/xhtml+xml'); print <<"END_OF_HTML"; <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Fruits</title> </head> <body> <form action="fruits.cgi"> <fieldset> <label for="fruit">Name of the fruit:</label> <input id="fruit" name="fruit_name" type="text" /> <input type="submit" /> </fieldset> </form> <iframe src="$iframe_document"> <a href="$iframe_document">resulting fruit</a> </iframe> </body> </html> END_OF_HTML 1;

    Read the article

  • .NET Type Conversion Issue: Simple but difficult

    - by jaderanderson
    Well, the question is kinda simple. I have a object defined as: public class FullListObject : System.Collections.ArrayList, IPagedCollection And when i try to: IPagedCollection pagedCollection = (IPagedCollection)value; It don't work... value is a FullListObject... this is my new code trying to get around a issue with the "is" operator. When the system tests (value is IPagedCollection) it never gets true for FullListObject. How to cast the object to another object with a interface type?

    Read the article

  • C# To VB.Net Conversion - array of class objects with initialisation

    - by mattryan
    can someone help me pls, im new to vb.net and im trying to work through the nhibernate firstsolkution sample (written in c#) and im struggling to convert this one bit. ive tried numerous convertors; telerik, developerfusion and a several others but none of the code produced will compile and i cant see the why... private readonly Product[] _products = new[] { new Product {Name = "Melon", Category = "Fruits"}, new Product {Name = "Pear", Category = "Fruits"}, new Product {Name = "Milk", Category = "Beverages"}, new Product {Name = "Coca Cola", Category = "Beverages"}, new Product {Name = "Pepsi Cola", Category = "Beverages"}, }; developer fusion gives Private ReadOnly _products As Product() = New () {New Product(), New Product(), New Product(), New Product(), New Product()} telerik gives Private ReadOnly _products As Product() = New () {New Product() With { _ .Name = "Melon", _ .Category = "Fruits" _ }, New Product() With { _ .Name = "Pear", _ .Category = "Fruits" _ }, New Product() With { _ .Name = "Milk", _ .Category = "Beverages" _ }, Nw Product() With { _ .Name = "Coca Cola", _ .Category = "Beverages" _ }, New Product() With { _ .Name = "Pepsi Cola", _ .Category = "Beverages" _ }} which seems the most useful except it complains about a type expected here "New () {..." ive tried various things just cant figure it out... what am i missing? am i just being dumb? or isnt there and equivilent? Cheers all

    Read the article

  • High-quality PDF to Word conversion in PHP?

    - by cletus
    What's the best way of converting PDF docs to Microsoft Word format in PHP? This can be either as a PHP script or calling a (Linux) executable (with proc_open()). It just needs to be relatively fast and produce quality Word documents (in 97/2000/2003 format). Commercial software is OK.

    Read the article

  • convert string to float without silent NaN/Inf conversion

    - by Peter Hansen
    I'd like convert strings to floats using Python 2.6 and later, but without silently converting things like 'NaN' and 'Inf'. Before 2.6, float("NaN") would raise a ValueError. Now it returns a float for which math.isnan() returns True, which is not useful behaviour for my application. Here's what I've got at the moment: import math def get_floats(source): for text in source.split(): try: val = float(text) if math.isnan(val) or math.isinf(val): raise ValueError yield val except ValueError: pass This is a generator, which I can supply with strings containing whitespace-separated sequences representing real numbers. I'd like it to yield only those fields which are purely numeric representations of floats, as in "1.23" or "-34e6", but not for example "NaN" or "-Inf". Test case: assert list(get_floats('1.23 -34e6 NaN -Inf')) == [1.23, -34000000.0] Please suggest alternatives you consider more elegant, even if they involve "look before you leap" (which is normally considered a lesser approach in Python).

    Read the article

< Previous Page | 8 9 10 11 12 13 14 15 16 17 18 19  | Next Page >