Search Results

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

Page 80/1488 | < Previous Page | 76 77 78 79 80 81 82 83 84 85 86 87  | Next Page >

  • latin1/unicode conversion problem with ajax request and special characters

    - by mfn
    Server is PHP5 and HTML charset is latin1 (iso-8859-1). With regular form POST requests, there's no problem with "special" characters like the em dash (–) for example. Although I don't know for sure, it works. Probably because there exists a representable character for the browser at char code 150 (which is what I see in PHP on the server for a literal em dash with ord). Now our application also provides some kind of preview mechanism via ajax: the text is sent to the server and a complete HTML for a preview is sent back. However, the ordinary char code 150 em dash character when sent via ajax (tested with GET and POST) mutates into something more: %E2%80%93. I see this already in the apache log. According to various sources I found, e.g. http://www.tachyonsoft.com/uc0020.htm , this is the UTF8 byte representation of em dash and my current knowledge is that JavaScript handles everything in Unicode. However within my app, I need everything in latin1. Simply said: just like a regular POST request would have given me that em dash as char code 150, I would need that for the translated UTF8 representation too. That's were I'm failing, because with PHP on the server when I try to decode it with either utf8_decode(...) or iconv('UTF-8', 'iso-8859-1', ...) but in both cases I get a regular ? representing this character (and iconv also throws me a notice: Detected an illegal character in input string ). My goal is to find an automated solution, but maybe I'm trying to be überclever in this case? I've found other people simply doing manual replacing with a predefined input/output set; but that would always give me the feeling I could loose characters. The observant reader will note that I'm behind on understanding the full impact/complexity with things about Unicode and conversion of chars and I definitely prefer to understand the thing as a whole then a simply manual mapping. thanks

    Read the article

  • UTF8 charset, diacritical elements, conversion problems - and Zend Framework form escaping

    - by imanc
    Hey, I am writing a webapp in ZF and am having serious issues with UTF8. It's using multi lingual content through Zend Form and it seems that ZF heavily escapes all of these characters and basically just won't show a field if there's diacritical elements 'é' and if I use the HTML entity equivalent e.g. é it gets escaped so that the user will see 'é'. Zend Form allows for having non escaped data, but trying to use this is confusing, and it seems it'd need to be used all over the place. So, I have been told that if the page and the text is in UTF8, no conversion to htmlentities is required. Is this true? And if the last question is true, then how do I convert the source text to UTF8? I am comfortable setting up apache so that it sends a default UTF8 charset heading, and also adding the charset meta tag to the html, but doing this I am still getting messed up encoding. I have also tried opening the translation csv file in TextWrangler on OSX as UTF8, but it has done nothing. Thanks! L

    Read the article

  • PHP & MySQL - Array to string conversion error problem.

    - by comma
    I keep getting an the following error of Array to string conversion error on this line listed below. How can I fix this problem? $skill = explode('', $_POST['skill']); Here is the PHP & MySQL code. $skill = explode('', $_POST['skill']); $experience = explode('', $_POST['experience']); $years = explode('', $_POST['years']); for ($s = 0; $s < count($skill); $s++){ for ($x = 0; $x < count($experience); $x++){ for ($g = 0; $g < count($years); $g++){ if (mysqli_num_rows($dbc) == 0) { $mysqli = mysqli_connect("localhost", "root", "", "sitename"); $dbc = mysqli_query($mysqli,"INSERT INTO learned_skills (user_id, skill, experience, years, date_created) VALUES ('" . $user_id . "', '" . $skill[$s] . "', '" . $experience[$x] . "', '" . $years[$g] . "', NOW())"); } if ($dbc == TRUE) { $dbc = mysqli_query($mysqli,"UPDATE learned_skills SET skill = '$skill', experience = '$experience', years = '$years', date_created = NOW() WHERE user_id = '$user_id'"); echo '<p class="changes-saved">Your changes have been saved!</p>'; } if (!$dbc) { print mysqli_error($mysqli); return; } } } }

    Read the article

  • Native Endians and Auto Conversion

    - by KnickerKicker
    so the following converts big endians to little ones uint32_t ntoh32(uint32_t v) { return (v << 24) | ((v & 0x0000ff00) << 8) | ((v & 0x00ff0000) >> 8) | (v >> 24); } works. like a charm. I read 4 bytes from a big endian file into char v[4] and pass it into the above function as ntoh32 (* reinterpret_cast<uint32_t *> (v)) that doesn't work - because my compiler (VS 2005) automatically converts the big endian char[4] into a little endian uint32_t when I do the cast. AFAIK, this automatic conversion will not be portable, so I use uint32_t ntoh_4b(char v[]) { uint32_t a = 0; a |= (unsigned char)v[0]; a <<= 8; a |= (unsigned char)v[1]; a <<= 8; a |= (unsigned char)v[2]; a <<= 8; a |= (unsigned char)v[3]; return a; } yes the (unsigned char) is necessary. yes it is dog slow. there must be a better way. anyone ?

    Read the article

  • C++ Implicit Conversion Operators

    - by Imbue
    I'm trying to find a nice inheritance solution in C++. I have a Rectangle class and a Square class. The Square class can't publicly inherit from Rectangle, because it cannot completely fulfill the rectangle's requirements. For example, a Rectangle can have it's width and height each set separately, and this of course is impossible with a Square. So, my dilemma. Square obviously will share a lot of code with Rectangle; they are quite similar. For examlpe, if I have a function like: bool IsPointInRectangle(const Rectangle& rect); it should work for a square too. In fact, I have a ton of such functions. So in making my Square class, I figured I would use private inheritance with a publicly accessible Rectangle conversion operator. So my square class looks like: class Square : private Rectangle { public: operator const Rectangle&() const; }; However, when I try to pass a Square to the IsPointInRectangle function, my compiler just complains that "Rectangle is an inaccessible base" in that context. I expect it to notice the Rectangle operator and use that instead. Is what I'm trying to do even possible? If this can't work I'm probably going to refactor part of Rectangle into MutableRectangle class. Thanks.

    Read the article

  • Dealing with Struts2 float conversion type

    - by Daniel Calderon Mori
    I have a question regarding float type conversion in Struts2. I have a form that contains a serie of normal input elements. A serie of textfields with an add button by the side of each one is included in the window. Clicking on one of this buttons has the effect of adding an input type "hidden" inside the form with the value of its correspondent textfield. That value will often be a float number that, this is very important, uses the point format (example: 1.34). The inputs created look like this: <input class="hidden_material" type="hidden" name="form[0].cantidad_formulacion" value='1.34'"> <input class="hidden_material" type="hidden" name="form[1].cantidad_formulacion" value='1.54'"> Anyway, the whole proccess is made correctly until the data is used by the server after the form submission. The numbers are present as if the point wouldn't have been placed in the number (using the example above, as 134). If a comma is used (as in 1,34), there wouldn't be a problem. But that will not be the case with the users of the system. How could I solve this problem?

    Read the article

  • Unit Conversion from feet to meters

    - by user1742419
    I have to write a program that reads in a length in feet and inches and outputs the equivalent length in meters and centimeters. I have to create three functions: one for input, one or more for calculating, and one for output; And include a loop that lets the user repeat this computation for new input values until the user says he or she wants to end the program. I can't seem to get the input from one function to be used in the conversion function and then outputted by the next function. How do I do that? Thank you. #include <iostream> #include <conio.h> using namespace std; double leng; void length(double leng); double conv(double leng); void output(double leng); int main() { length(leng); conv(leng); output(leng); _getche(); return 0; } void length(double leng) { cout<<"Enter a length in feet, then enter a length in inches if needed: "; cin>>leng; return; } double conv(double leng) { return leng = leng * .3048; } void output(double leng) { cout<<"Your input is converted to "<<leng; return; }

    Read the article

  • ASP.NET List Control

    - by Ricardo Peres
    Today I developed a simple control for generating lists in ASP.NET, something that the base class library does not contain; it allows for nested lists where the list item types and images can be configured on a list by list basis. Since it was a great fun to develop, I'd like to share it here. Here is the code: [ParseChildren(true)] [PersistChildren(false)] public class List: WebControl { public List(): base("ul") { this.Items = new List(); this.ListStyleType = ListStyleType.Auto; this.ListStyleImageUrl = String.Empty; this.CommonCssClass = String.Empty; this.ContainerCssClass = String.Empty; } [DefaultValue(ListStyleType.Auto)] public ListStyleType ListStyleType { get; set; } [DefaultValue("")] [UrlProperty("*.png;*.gif;*.jpg")] public String ListStyleImageUrl { get; set; } [DefaultValue("")] [CssClassProperty] public String CommonCssClass { get; set; } [DefaultValue("")] [CssClassProperty] public String ContainerCssClass { get; set; } [Browsable(false)] [PersistenceModeAttribute(PersistenceMode.InnerProperty)] public List Items { private set; get; } protected override void Render(HtmlTextWriter writer) { String cssClass = String.Join(" ", new String [] { this.CssClass, this.ContainerCssClass }); if (cssClass.Trim().Length != 0) { this.CssClass = cssClass; } if (String.IsNullOrEmpty(this.ListStyleImageUrl) == false) { this.Style[ HtmlTextWriterStyle.ListStyleImage ] = String.Format("url('{0}')", this.ResolveClientUrl(this.ListStyleImageUrl)); } if (this.ListStyleType != ListStyleType.Auto) { switch (this.ListStyleType) { case ListStyleType.Circle: case ListStyleType.Decimal: case ListStyleType.Disc: case ListStyleType.None: case ListStyleType.Square: this.Style [ HtmlTextWriterStyle.ListStyleType ] = this.ListStyleType.ToString().ToLower(); break; case ListStyleType.LowerAlpha: this.Style [ HtmlTextWriterStyle.ListStyleType ] = "lower-alpha"; break; case ListStyleType.LowerRoman: this.Style [ HtmlTextWriterStyle.ListStyleType ] = "lower-roman"; break; case ListStyleType.UpperAlpha: this.Style [ HtmlTextWriterStyle.ListStyleType ] = "upper-alpha"; break; case ListStyleType.UpperRoman: this.Style [ HtmlTextWriterStyle.ListStyleType ] = "upper-roman"; break; } } base.Render(writer); } protected override void RenderChildren(HtmlTextWriter writer) { foreach (ListItem item in this.Items) { this.writeItem(item, this, 0); } base.RenderChildren(writer); } private void writeItem(ListItem item, Control control, Int32 depth) { HtmlGenericControl li = new HtmlGenericControl("li"); control.Controls.Add(li); if (String.IsNullOrEmpty(this.CommonCssClass) == false) { String cssClass = String.Join(" ", new String [] { this.CommonCssClass, this.CommonCssClass + depth }); li.Attributes [ "class" ] = cssClass; } foreach (String key in item.Attributes.Keys) { li.Attributes[key] = item.Attributes [ key ]; } li.InnerText = item.Text; if (item.ChildItems.Count != 0) { HtmlGenericControl ul = new HtmlGenericControl("ul"); li.Controls.Add(ul); if (String.IsNullOrEmpty(this.ContainerCssClass) == false) { ul.Attributes["class"] = this.ContainerCssClass; } if ((item.ListStyleType != ListStyleType.Auto) || (String.IsNullOrEmpty(item.ListStyleImageUrl) == false)) { if (String.IsNullOrEmpty(item.ListStyleImageUrl) == false) { ul.Style[HtmlTextWriterStyle.ListStyleImage] = String.Format("url('{0}');", this.ResolveClientUrl(item.ListStyleImageUrl)); } if (item.ListStyleType != ListStyleType.Auto) { switch (this.ListStyleType) { case ListStyleType.Circle: case ListStyleType.Decimal: case ListStyleType.Disc: case ListStyleType.None: case ListStyleType.Square: ul.Style[ HtmlTextWriterStyle.ListStyleType ] = item.ListStyleType.ToString().ToLower(); break; case ListStyleType.LowerAlpha: ul.Style [ HtmlTextWriterStyle.ListStyleType ] = "lower-alpha"; break; case ListStyleType.LowerRoman: ul.Style [ HtmlTextWriterStyle.ListStyleType ] = "lower-roman"; break; case ListStyleType.UpperAlpha: ul.Style [ HtmlTextWriterStyle.ListStyleType ] = "upper-alpha"; break; case ListStyleType.UpperRoman: ul.Style [ HtmlTextWriterStyle.ListStyleType ] = "upper-roman"; break; } } } foreach (ListItem childItem in item.ChildItems) { this.writeItem(childItem, ul, depth + 1); } } } } [Serializable] [ParseChildren(true, "ChildItems")] public class ListItem: IAttributeAccessor { public ListItem() { this.ChildItems = new List(); this.Attributes = new Dictionary(); this.Text = String.Empty; this.Value = String.Empty; this.ListStyleType = ListStyleType.Auto; this.ListStyleImageUrl = String.Empty; } [DefaultValue(ListStyleType.Auto)] public ListStyleType ListStyleType { get; set; } [DefaultValue("")] [UrlProperty("*.png;*.gif;*.jpg")] public String ListStyleImageUrl { get; set; } [DefaultValue("")] public String Text { get; set; } [DefaultValue("")] public String Value { get; set; } [Browsable(false)] public List ChildItems { get; private set; } [Browsable(false)] public Dictionary Attributes { get; private set; } String IAttributeAccessor.GetAttribute(String key) { return (this.Attributes [ key ]); } void IAttributeAccessor.SetAttribute(String key, String value) { this.Attributes [ key ] = value; } } [Serializable] public enum ListStyleType { Auto = 0, Disc, Circle, Square, Decimal, LowerRoman, UpperRoman, LowerAlpha, UpperAlpha, None } SyntaxHighlighter.config.clipboardSwf = 'http://alexgorbatchev.com/pub/sh/2.0.320/scripts/clipboard.swf'; SyntaxHighlighter.brushes.CSharp.aliases = ['c#', 'c-sharp', 'csharp']; SyntaxHighlighter.all();

    Read the article

  • Error 404 after rewrite query strings with htaccess

    - by Cristian
    I'm trying to redirect the URLs of a client's website like this: www.localsite.com/immobile.php?id_immobile=24 In something like this: www.localsite.com/immobile/24.php I'm using this rule in .htaccess but it returns a 404 error page. RewriteEngine On RewriteCond %{QUERY_STRING} ^id_immobile=([0-9]*)$ RewriteRule ^immobile\.php$ http://localsite.com/immobile/%1.php? [L] I have tried many other rules, but none work. What can I do?

    Read the article

  • The provider did not return a ProviderManifestToken string Entity Framework

    - by PearlFactory
    Moved from Home to work and went to fire up my project and after long pause "The provider did not return a ProviderManifestToken string" or even More Abscure ProviderIncompatable Exception Now after 20 mins of chasing my tail re different ver of EntityFramework 4.1 vs 4.2...blahblahblah Look inside at the inner exception A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible DOH!!!! Or a clean translation is that it cant find SQL or is offline or not running. SO check the power is on/Service running or as in my case Edit web.config & change back to Work SQL box   Hope you dont have this pain as the default errors @ the moment suck balls in the EntityFramework 4.XX releases   Cheers

    Read the article

  • Find and Replace String in filenames

    - by shekhar
    I have thousands of files with no specific extensions. What I need to do is to search for a sting in filename and replace with other string and further search for second string and replace with any other string and so on. I.e.: I have multiple strings to replace with other multiple strings. It may be like: "abc" in filename replaced with "def" * String "abc" may be in many files "jkl" in filename replaced with "srt" * String "jkl" may be in many files "pqr" in filename replaced with "xyz" * String "pqr" may be in many files I am currently using excel macro to get the file names in excel and then preserving original names in one column and replacing desired in the content copied in other column. then I create a batch file for the same. Like: rename Path\OriginalName1 NewName1 rename Path\OriginalName2 NewName2 Problem with the above procedure is that it takes a lot of time as the files are many. And As I am using excel 2003 there is limitation on number of rows as well. I need a script in batch like: replacestr abc with def replacestr pqr with xyz in a single directory. Will it be better to do in unix script?

    Read the article

  • String Formatting with concatenation or substitution

    - by Davio
    This is a question about preferences. Assume a programming language offers these two options to make a string with some variables: "Hello, my name is ". name ." and I'm ". age ." years old." StringFormat("Hello, my name is $0 and I'm $1 years old.", name, age) Which do you prefer and why? I have found myself using both without any clear reason to pick either. Considering micro-optimizations is not within the scope of this question. Localization has been mentioned as a reason to go with option #2 and I think it's a very valid reason and deserves to be mentioned here. However, would opinions differ based on aesthetic viewpoints?

    Read the article

  • IIS 6 nested virtual directory redirection

    - by threedaysatsea
    We're running IIS 6 on a WinServer2k3 box and we're having some trouble with the following problem: E-mails were sent out to users asking them to go to the following URL: alias.contoso.com/directory2/view.aspx?queryparam1=no&queryparam2=blue However, the URLS are actually supposed to be: server.contoso.com/directory2/view.aspx?queryparam1=no&queryparam2=blue It's too late to recall all of the e-mails, and we'd like to redirect traffic to make this as seamless as possible for our users. The real problem here is that the server (server.contoso.com) is hosting the alias (alias.contoso.com) as a redirect thusly, and the existing redirect we need to keep functional: Default Web Site (server.contoso.com) --Directory1 --Directory2 --Directory3 Redirection to Directory3 (alias.contoso.com) --Essentially alias.contoso.com will take the user to server.contoso.com/Directory3 Is there any way to host a separate redirect inside of the existing redirect? We need to keep alias.contoso.com taking the user to server.contoso.com/Directory3 but also make alias.contoso.com/directory2/view.aspx?queryparam1=no&queryparam2=blue point to server.contoso.com/directory2/view.aspx?queryparam1=no&queryparam2=blue Any tips? Is this even possible?

    Read the article

  • Compare a variable that can have numeric or string as value

    - by Tarun
    I have a variable named Seconds_Behind_Master from one of my scripts. The problem is that this variable can either have a numeric value or can also take a string NULL as its value. Now, when I try to execute this script in shell it gets executed but gives a warning like this: [: Illegal number: NULL I believe it is due to the fact that in this case the value is NULL but when it compares it with numeral value 60 it gives this warning. How can I rectify it? Here is the piece of code: Seconds_Behind_Master=$Show_Slave_Status | grep "Seconds_Behind_Master" | awk -F": " {' print $2 '} if [ "$Seconds_Behind_Master" -ge "60" ]; then echo "replication delayed greater than or equal to 60." else if [ "$Seconds_Behind_Master" = "NULL" ]; then echo "Delay is Null." fi fi

    Read the article

  • robots.txt dissalow url containing string with a '/' at the end

    - by thanili
    i have a website with thousands of dynamic pages. I want to use the robots.txt file in order to dissalow certain url patterns corresponding to pages with duplicate content. For example i have a page for article itemA belonging to category catA/subcatA, with URL: /catA/subcatA/itemA this is the URL that i want to be indexed from google. this article is also visible via tagging in various other places in the web site. The URLs produced via tagging is like: /tagA1/itemA this URL i want NOT to be indexed from google. However i want to have indexed all tag listings: /tagA1 so how can i achieve this? dissalow URLs of including a specific string with a '/' at the end? /tagA1/ itemA - dissalow /tagA1 - allow

    Read the article

  • Output the total number of String Characters [migrated]

    - by Programmerwannabe
    My Question is what method should I use if I wanted to get the total number of characters a user inputs? without using arrays, i tried using .length() but it did not return all characters say from the first and lastname, it only returned the first name. Here's an example of my code. (Please dont laugh im really new in programming :) ) System.out.print("Enter your first and last name: "); String yourName = keyboard.next(); System.out.println("Your name has a total of " + yourName.length() + " numbers"); what happened was if i enter say "Neo Matrix" it would only return 3. I appreciate any help. thank you!

    Read the article

  • Why did this work with Visual C++, but not with gcc?

    - by Carlos Nunez
    I've been working on a senior project for the last several months now, and a major sticking point in our team's development process has been dealing wtih rifts between Visual-C++ and gcc. (Yes, I know we all should have had the same development environment.) Things are about finished up at this point, but I ran into a moderate bug just today that had me wondering whether Visual-C++ is easier on newbies (like me) by design. In one of my headers, there is a function that relies on strtok to chop up a string, do some comparisons and return a string with a similar format. It works a little something like the following: int main() { string a, b, c; //Do stuff with a and b. c = get_string(a,b); } string get_string(string a, string b) { const char * a_ch, b_ch; a_ch = strtok(a.c_str(),","); b_ch = strtok(b.c_str(),","); } strtok is infamous for being great at tokenizing, but equally great at destroying the original string to be tokenized. Thus, when I compiled this with gcc and tried to do anything with a or b, I got unexpected behavior, since the separator used was completely removed in the string. Here's an example in case I'm unclear; if I set a = "Jim,Bob,Mary" and b="Grace,Soo,Hyun", they would be defined as a="JimBobMary" and b="GraceSooHyun" instead of staying the same like I wanted. However, when I compiled this under Visual C++, I got back the original strings and the program executed fine. I tried dynamically allocating memory to the strings and copying them the "standard" way, but the only way that worked was using malloc() and free(), which I hear is discouraged in C++. While I'm curious about that, the real question I have is this: Why did the program work when compiled in VC++, but not with gcc? (This is one of many conflicts that I experienced while trying to make the code cross-platform.) Thanks in advance! -Carlos Nunez

    Read the article

  • Why does Jcreator show iIlegal start of expression?

    - by Inusual Whisper Sinclair
    I am new at programming and currently in our classes we are learning java. I am trying to create a routine in which I need to use String variables only. Below it is the code in which I am working with: public static void main(String[] args) throws java.io.IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System. in )); PrintStream out = System.out; String hair.equals("damagedHair"); cutHair(marvin); cleanHair(michelle); for (int i = 0; i < 2; i++) { static void cutHair(String marvin) { String cabello; marvin.equals(hair); if (marvin.equals("damagedHair")) { cabello.equals("newHaircut"); result(hair); } static void cleanHair(String michelle) { String hair; michelle.equals(hair); if (michelle.equals(newHaircut)) { hair.equals("putShampooAndConditioner"); result(hair); } static void result(String pHair) {; PrintStream out = System.out; out.println("============="); out.println(pHair); out.println("============="); } } Jcreator is giving me an error that says Illegal start of expression and also java 50 error ';' expected. I am not sure why is this coming up and I am a little confused as to whether I am doing something I am not supposed to and how to correct it. Sorry about the double posting, this is the right message. Need some help from you guys to figure this out. Thanks in advanced!

    Read the article

  • String Sharing/Reference issue with objects in Delphi

    - by jenakai123
    My application builds many objects in memory based on filenames (among other string based information). I was hoping to optimise memory usage by storing the path and filename separately, and then sharing the path between objects in the same path. I wasn't trying to look at using a string pool or anything, basically my objects are sorted so if I have 10 objects with the same path I want objects 2-10 to have their path "pointed" at object 1's path (eg object[2].Path=object[1].Path); I have a problem though, I don't believe that my objects are in fact sharing a reference to the same string after I think I am telling them to (by the object[2].Path=object[1].Path assignment). When I do an experiment with a string list and set all the values to point to the first value in the list I can see the "memory conservation" in action, but when I use objects I see absolutely no change at all, admittedly I am only using task manager (private working set) to watch for memory use changes. Here's a contrived example, I hope this makes sense. I have an object: TfileObject=class(Tobject) FpathPart: string; FfilePart: string; end; Now I create 1,000,000 instances of the object, using a new string for each one: var x: integer; MyFilePath: string; fo: TfileObject; begin for x := 1 to 1000000 do begin // create a new string for every iteration of the loop MyFilePath:=ExtractFilePath(Application.ExeName); fo:=TfileObject.Create; fo.FpathPart:=MyFilePath; FobjectList.Add(fo); end; end; Run this up and task manager says I am using 68MB of memory or something. (Note that if I allocated MyFilePath outside of the loop then I do save memory because of 1 instance of the string, but this is a contrived example and not actually how it would happen in the app). Now I want to "optimise" my memory usage by making all objects share the same instance of the path string, since it's the same value: var x: integer; begin for x:=1 to FobjectList.Count-1 do begin TfileObject(FobjectList[x]).FpathPart:=TfileObject(FobjectList[0]).FpathPart; end; end; Task Manager shows absouletly no change. However if I do something similar with a TstringList: var x: integer; begin for x := 1 to 1000000 do begin FstringList.Add(ExtractFilePath(Application.ExeName)); end; end; Task Manager says 60MB memory use. Now optimise with: var x: integer; begin for x := 1 to FstringList.Count - 1 do FstringList[x]:=FstringList[0]; end; Task Manager shows the drop in memory usage that I would expect, now 10MB. So I seem to be able to share strings in a string list, but not in objects. I am obviously missing something conceptually, in code or both! I hope this makes sense, I can really see the ability to conserve memory using this technique as I have a lot of objects all with lots of string information, that data is sorted in many different ways and I would like to be able to iterate over this data once it is loaded into memory and free some of that memory back up again by sharing strings in this way. Thanks in advance for any assistance you can offer.

    Read the article

  • Challenge: Neater way of currying or partially applying C#4's string.Join

    - by Damian Powell
    Background I recently read that .NET 4's System.String class has a new overload of the Join method. This new overload takes a separator, and an IEnumerable<T> which allows arbitrary collections to be joined into a single string without the need to convert to an intermediate string array. Cool! That means I can now do this: var evenNums = Enumerable.Range(1, 100) .Where(i => i%2 == 0); var list = string.Join(",",evenNums); ...instead of this: var evenNums = Enumerable.Range(1, 100) .Where(i => i%2 == 0) .Select(i => i.ToString()) .ToArray(); var list = string.Join(",", evenNums); ...thus saving on a conversion of every item to a string, and then the allocation of an array. The Problem However, being a fan of the functional style of programming in general, and method chaining in C# in particular, I would prefer to be able to write something like this: var list = Enumerable.Range(1, 100) .Where(i => i%2 == 0) .string.Join(","); This is not legal C# though. The closest I've managed to get is this: var list = Enumerable.Range(1, 100) .Where(i => i%2 == 0) .ApplyTo( Functional.Curry<string, IEnumerable<object>, string> (string.Join)(",") ); ...using the following extension methods: public static class Functional { public static TRslt ApplyTo<TArg, TRslt>(this TArg arg, Func<TArg, TRslt> func) { return func(arg); } public static Func<T1, Func<T2, TResult>> Curry<T1, T2, TResult>(this Func<T1, T2, TResult> func) { Func<Func<T1, T2, TResult>, Func<T1, Func<T2, TResult>>> curried = f => x => y => f(x, y); return curried(func); } } This is quite verbose, requires explicit definition of the parameters and return type of the string.Join overload I want to use, and relies upon C#4's variance features because we are defining one of the arguments as IEnumerable rather than IEnumerable. The Challenge Can you find a neater way of achieving this using the method-chaining style of programming?

    Read the article

  • Android: Getting Error: Conversion to Dalvik format failed

    - by Rupesh C
    I am building an app on android and running into an error and while searching on net, came across your posting on this and changed the eclipse.ini to increase Xms and Xmx params but still this error does not go away. I am using Eclipse IDE for Java with Andrioid SDK 2.1 on Mac OS. Please help or please point me to someone who might know. Btw, this error only happens when i add external jar files (which i need for my project). here are the list of external jar files that i have in my classpath.) // httpclient-4.0.1.jar from apache // httpcore -4.0.1.jarfrom apache // commons-codec-1.3.jar from apache //commons-logging-1.1.1.jar from apache // json_simple-1.1.jar from google Here is the complete error: UNEXPECTED TOP-LEVEL EXCEPTION: java.lang.IllegalArgumentException: already added: Lorg/apache/commons/logging/impl/AvalonLogger; [2010-05-02 21:57:05 - MyApp]     at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123) [2010-05-02 21:57:05 - MyApp]     at com.android.dx.dex.file.DexFile.add(DexFile.java:143) [2010-05-02 21:57:05 - MyApp]     at com.android.dx.command.dexer.Main.processClass(Main.java:301) [2010-05-02 21:57:05 - MyApp]     at com.android.dx.command.dexer.Main.processFileBytes(Main.java:278) [2010-05-02 21:57:05 - MyApp]     at com.android.dx.command.dexer.Main.access$100(Main.java:56) [2010-05-02 21:57:05 - MyApp]     at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:229) [2010-05-02 21:57:05 - MyApp]     at com.android.dx.cf http://com.android.dx.cf.direct.ClassPathOpener.pro .direct.ClassPathOpener.processArchive(ClassPathOpener.java:244) [2010-05-02 21:57:05 - MyApp]     at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:130) [2010-05-02 21:57:05 - MyApp]     at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:108) [2010-05-02 21:57:05 - MyApp]     at com.android.dx.command.dexer.Main.processOne(Main.java:247) [2010-05-02 21:57:05 - MyApp]     at com.android.dx.command.dexer.Main.processAllFiles(Main.java:183) [2010-05-02 21:57:05 - MyApp]     at com.android.dx.command.dexer.Main.run(Main.java:139) [2010-05-02 21:57:05 - MyApp]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [2010-05-02 21:57:05 - MyApp]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [2010-05-02 21:57:05 - MyApp]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [2010-05-02 21:57:05 - MyApp]     at java.lang.reflect.Method.invoke(Method.java:592) [2010-05-02 21:57:05 - MyApp]     at com.android.ide.eclipse.adt.internal.sdk.DexWrapper.run(Unknown Source) [2010-05-02 21:57:05 - MyApp]     at com.android.ide.eclipse.adt.internal.build.ApkBuilder.executeDx(Unknown Source) [2010-05-02 21:57:05 - MyApp]     at com.android.ide.eclipse.adt.internal.build.ApkBuilder.build(Unknown Source) [2010-05-02 21:57:05 - MyApp]     at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:627) [2010-05-02 21:57:05 - MyApp]     at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42) [2010-05-02 21:57:05 - MyApp]     at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:170) [2010-05-02 21:57:05 - MyApp]     at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:201) [2010-05-02 21:57:05 - MyApp]     at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:253) [2010-05-02 21:57:05 - MyApp]     at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42) [2010-05-02 21:57:05 - MyApp]     at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:256) [2010-05-02 21:57:05 - MyApp]     at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:309) [2010-05-02 21:57:05 - MyApp]     at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:341) [2010-05-02 21:57:05 - MyApp]     at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:140) [2010-05-02 21:57:05 - MyApp]     at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:238) [2010-05-02 21:57:05 - MyApp]     at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55) [2010-05-02 21:57:05 - MyApp] 4 errors; aborting [2010-05-02 21:57:05 - MyApp] Conversion to Dalvik format failed with error 1 Thanks, Rupesh

    Read the article

  • Transposing and Untransposing a String in java

    - by Will
    I have been working on two methods that will Transpose and Untranspose a String respectively. The solutions that I have come up with both work to the best of my knowledge. I just want to know if I could have solved these problems in a simpler way. My code seems like it is too long for the task that is being performed. The first method, transpose(), will take a String as a parameter and transpose it. If "bridge" is entered, the output will be "bergid". Likewise, with the unTranspose() method, if the user enters "bergid", the output will be "bridge". public void transpose( String s ) { String t = ""; int end = s.length() - 1; for ( int i = 0; i < s.length() / 2; i++ ) { t += Character.toString( s.charAt( i ) ) + Character.toString( s.charAt( end ) ); end--; } // Lenth of String is odd if ( s.length() % 2 == 1 ) { // add character in middle of String to the end of the new String t+= Character.toString( s.charAt( s.length() / 2 ) ); } System.out.println( t ); } public void unTranspose( String s ) { String t = ""; // Length of String is odd if ( s.length() % 2 == 1 ) { for ( int i = 0; i < s.length(); i+=2 ) { t+= Character.toString( s.charAt( i ) ); } for ( int i = s.length() - 2; i > 0; i -= 2 ) { t += Character.toString( s.charAt( i ) ); } System.out.println( t ); } // Length of String is even else if ( s.length() % 2 == 0 ) { for ( int i = 0; i < s.length() - 1; i+=2 ) { t+= Character.toString( s.charAt( i ) ); } for ( int i = s.length() - 1; i > 0; i -= 2 ) { t+= Character.toString( s.charAt( i ) ); } System.out.println( t ); } } My code looks horrible. I'm still not used to formatting my code correctly. Please bear with me. Thanks for your time

    Read the article

  • conversion of DNA to Protein - c structure issue

    - by sam
    I am working on conversion of DNA sequence to Protein sequence. I had completed all program only one error I found there is of structure. dna_codon is a structure and I am iterating over it.In first iteration it shows proper values of structure but from next iteration, it dont show the proper value stored in structure. Its a small error so do not think that I havnt done anything and downvote. I am stucked here because I am new in c for structures. CODE : #include <stdio.h> #include<string.h> void main() { int i, len; char short_codons[20]; char short_slc[1000]; char sequence[1000]; struct codons { char amino_acid[20], slc[20], dna_codon[40]; }; struct codons c1 [20]= { {"Isoleucine", "I", "ATT, ATC, ATA"}, {"Leucine", "L", "CTT, CTC, CTA, CTG, TTA, TTG"}, {"Valine", "V", "GTT, GTC, GTA, GTG"}, {"Phenylalanine", "F", "TTT, TTC"}, {"Methionine", "M", "ATG"}, {"Cysteine", "C", "TGT, TGC"}, {"Alanine", "A", "GCT, GCC, GCA, GCG"}, {"Proline", "P", "CCT, CCC, CCA,CCG "}, {"Threonine", "T", "ACT, ACC, ACA, ACG"}, {"Serine", "S", "TCT, TCC, TCA, TCG, AGT, AGC"}, {"Tyrosine", "Y", "TAT, TAC"}, {"Tryptophan", "W", "TGG"}, {"Glutamine", "Q", "CAA, CAG"}, {"Aspargine","N" "AAT, AAC"}, {"Histidine", "H", "CAT, CAC"}, {"Glutamic acid", "E", "GAA, GAG"}, {"Aspartic acid", "D", "GAT, GAC"}, {"Lysine", "K", "AAA, AAG"}, {"Arginine", "R", "CGT, CGC, CGA, CGG, AGA, AGG"}, {"Stop codons", "Stop", "AA, TAG, TGA"} }; int count = 0; printf("Enter the sequence: "); gets(sequence); char *input_string = sequence; char *tmp_str = input_string; int k; char *pch; while (*input_string != '\0') { char string_3l[4] = {'\0'}; strncpy(string_3l, input_string, 3); printf("\n-----------%s & %s----------", string_3l, tmp_str ); for(k=0;k<20;k++) { //printf("@REAL - %s", c1[0].dna_codon); printf("@ %s", c1[k].dna_codon); int x; x = c1[k].dna_codon; pch = strtok(x, ","); while (pch != NULL) { printf("\n%d : %s with %s", k, string_3l, pch); count=strcmp(string_3l, pch); if(count==0) { strcat(short_slc, c1[k].slc); printf("\n==>%s", short_slc); } pch = strtok (NULL, " ,.-"); } } input_string = input_string+3; } printf("\nProtien sequence is : %s\n", short_slc); } INPUT : TAGTAG OUTPUT : If you see output of printf("\n-----------%s & %s----------", string_3l, tmp_str ); in both iterations, we found that values defined in structure are reduced. I want to know why structure reduces it or its my mistake? because I am stucked here

    Read the article

  • Objective-C Decimal to Base 16 Hex conversion

    - by JustinXXVII
    Does anyone have a code snippet or a class that will take a long long and turn it into a 16 byte Hex string? I'm looking to turn data like this long long decimalRepresentation = 1719886131591410351; and turn it into this //Base 16 Hex Output: 17DE435307A07300 The %x operator doesn't want to work for me NSLog(@"Hex: %x",decimalRepresentation); //console : "Hex: 7a072af" As you can see that's not even close. Any help is truly appreciated!

    Read the article

< Previous Page | 76 77 78 79 80 81 82 83 84 85 86 87  | Next Page >