Search Results

Search found 36172 results on 1447 pages for 'unicode string'.

Page 45/1447 | < Previous Page | 41 42 43 44 45 46 47 48 49 50 51 52  | Next Page >

  • String comparison in Python: is vs. ==

    - by Coquelicot
    I noticed a Python script I was writing was acting squirrelly, and traced it to an infinite loop, where the loop condition was "while line is not ''". Running through it in the debugger, it turned out that line was in fact ''. When I changed it to != rather than 'is not', it worked fine. I did some searching, and found this question, the top answer to which seemed to be just what I needed. Except the answer it gave was counter to my experience. Specifically, the answerer wrote: For all built-in Python objects (like strings, lists, dicts, functions, etc.), if x is y, then x==y is also True. I double-checked the type of the variable, and it was in fact of type str (not unicode or something). Is his answer just wrong, or is there something else afoot? Also, is it generally considered better to just use '==' by default, even when comparing int or Boolean values? I've always liked to use 'is' because I find it more aesthetically pleasing and pythonic (which is how I fell into this trap...), but I wonder if it's intended to just be reserved for when you care about finding two objects with the same id.

    Read the article

  • C++, using stack.h read a string, then display it in reverse

    - by user1675108
    For my current assignment, I have to use the following header file, #ifndef STACK_H #define STACK_H template <class T, int n> class STACK { private: T a[n]; int counter; public: void MakeStack() { counter = 0; } bool FullStack() { return (counter == n) ? true : false ; } bool EmptyStack() { return (counter == 0) ? true : false ; } void PushStack(T x) { a[counter] = x; counter++; } T PopStack() { counter--; return a[counter]; } }; #endif To write a program that will take a sentence, store it into the "stack", and then display it in reverse, and I have to allow the user to repeat this process as much as they want. The thing is, I am NOT allowed to use arrays (otherwise I wouldn't need help with this), and am finding myself stumped. To give an idea of what I am attempting, here is my code as of posting, which obviously does not work fully but is simply meant to give an idea of the assignment. #include <iostream> #include <cstring> #include <ctime> #include "STACK.h" using namespace std; int main(void) { auto time_t a; auto STACK<char, 256> s; auto string curStr; auto int i; // Displays the current time and date time(&a); cout << "Today is " << ctime(&a) << endl; s.MakeStack(); cin >> curStr; i = 0; do { s.PushStack(curStr[i]); i++; } while (s.FullStack() == false); do { cout << s.PopStack(); } while (s.EmptyStack() == false); return 0; } // end of "main" **UPDATE This is my code currently #include <iostream> #include <string> #include <ctime> #include "STACK.h" using namespace std; time_t a; STACK<char, 256> s; string curStr; int i; int n; // Displays the current time and date time(&a); cout << "Today is " << ctime(&a) << endl; s.MakeStack(); getline(cin, curStr); i = 0; n = curStr.size(); do { s.PushStack(curStr[i++]); i++; }while(i < n); do { cout << s.PopStack(); }while( !(s.EmptyStack()) ); return 0;

    Read the article

  • Custom string class (C++)

    - by Sanctus2099
    Hey guys. I'm trying to write my own C++ String class for educational and need purposes. The first thing is that I don't know that much about operators and that's why I want to learn them. I started writing my class but when I run it it blocks the program but does not do any crash. Take a look at the following code please before reading further: class CString { private: char* cstr; public: CString(); CString(char* str); CString(CString& str); ~CString(); operator char*(); operator const char*(); CString operator+(const CString& q)const; CString operator=(const CString& q); }; First of all I'm not so sure I declared everything right. I tried googleing about it but all the tutorials about overloading explain the basic ideea which is very simple but lack to explain how and when each thing is called. For instance in my = operator the program calls CString(CString& str); but I have no ideea why. I have also attached the cpp file below: CString::CString() { cstr=0; } CString::CString(char *str) { cstr=new char[strlen(str)]; strcpy(cstr,str); } CString::CString(CString& q) { if(this==&q) return; cstr = new char[strlen(q.cstr)+1]; strcpy(cstr,q.cstr); } CString::~CString() { if(cstr) delete[] cstr; } CString::operator char*() { return cstr; } CString::operator const char* () { return cstr; } CString CString::operator +(const CString &q) const { CString s; s.cstr = new char[strlen(cstr)+strlen(q.cstr)+1]; strcpy(s.cstr,cstr); strcat(s.cstr,q.cstr); return s; } CString CString::operator =(const CString &q) { if(this!=&q) { if(cstr) delete[] cstr; cstr = new char[strlen(q.cstr)+1]; strcpy(cstr,q.cstr); } return *this; } For testing I used a code just as simple as this CString a = CString("Hello") + CString(" World"); printf(a); I tried debugging it but at a point I get lost. First it calls the constructor 2 times for "hello" and for " world". Then it get's in the + operator which is fine. Then it calls the constructor for the empty string. After that it get's into "CString(CString& str)" and now I'm lost. Why is this happening? After this I noticed my string containing "Hello World" is in the destructor (a few times in a row). Again I'm very puzzeled. After converting again from char* to Cstring and back and forth it stops. It never get's into the = operator but neither does it go further. printf(a) is never reached. I use VisualStudio 2010 for this but it's basically just standard c++ code and thus I don't think it should make that much of a difference

    Read the article

  • if string is alphabetically greater than other string in objective

    - by Jonathan
    I'm trying to use an if statement to work out which of 2 strings comes first alphabetically. Like with numbers and greater and less than: if (1 < 2) { just with strings: if(@"ahello" < @"bhello") { Or would I have to have a string containing all the letters and then check the index of the first char in each string and see which index is greater, and the index that is less than the other comes first in the alphabet and then if they are equal move on to the next char and repeat?

    Read the article

  • C# Linq - Cannot implicitly convert IEnumerable<string> to List<string>

    - by JL
    I have a List defined like this : public List<string> AttachmentURLS; I am adding items to the list like this: instruction.AttachmentURLS = curItem.Attributes["ows_Attachments"].Value.Split(';').ToList().Where(Attachment => !String.IsNullOrEmpty(Attachment)); But I am getting this error: Cannot implicitly convert IEnumerable to List What am I doing wrong?

    Read the article

  • string or nsstring with string

    - by joels
    Lets assume myProp is @property (retain) NSString * myProp and synthesized for us.... self.myProp = @"some value";//string literal? self.myProp = [NSString stringWithString:@"some value"]; Is there a difference here? Is the first one a string literal that doesnt get autoreleased or is it just in memory for it's current scope and I dont have to worry about it?

    Read the article

  • Ruby String accent error: More than meet the eyes

    - by Fabiano PS
    I'm having a real trouble to get accents right, and I believe this may happen to most Latin languages, in my case, portuguese I have a string that come as parameter and I must get the first letter and upcase it! That should be trivial in ruby, but here is the catch: s1 = 'alow'; s1.size #=> 4 s2 = 'álow'; s2.size #=> 5 s1[0,1] #=> "a" s2[0,1] #=> "\303" s1[0,1].upcase #=> 'A' s2[0,1].upcase #=> '\303' !!! s1[0,1].upcase + s1[1,100] #=> "Alow" OK s2[0,1].upcase + s2[1,100] #=> "álow" NOT OK I'd like to make it generic, Any help? [EDIT] I found that Rails Strings can be cast to Multibytes as seen in class ../active_support/core_ext/string/multibyte.rb, just using: s2.mb_chars[0,1].upcase.to_s #=> "Á" Still, @nsdk approach is easier to use =)

    Read the article

  • comparison between string literal

    - by wiso
    This very simple code: #include <iostream> using namespace std; void exec(char* option) { cout << "option is " << option << endl; if (option == "foo") cout << "option foo"; else if (option == "bar") cout << "opzion bar"; else cout << "???"; cout << endl; } int main() { char opt[] = "foo"; exec(opt); return 0; } generate two warning: comparison with string literal results in unspecified behaviour. Can you explain why exactly this code doesn't work, but if I change char opt[] to char *opt it works, but generates the warning? Is it related to the \0 termination? What is the difference between the two declaration of opt? What if I use const qualifier? The solution is to use std::string?

    Read the article

  • Approximate string matching with a letter confusion matrix?

    - by zigglenaut
    I'm trying to model a phonetic recognizer that has to isolate instances of words (strings of phones) out of a long stream of phones that doesn't have gaps between each word. The stream of phones may have been poorly recognized, with letter substitutions/insertions/deletions, so I will have to do approximate string matching. However, I want the matching to be phonetically-motivated, e.g. "m" and "n" are phonetically similar, so the substitution cost of "m" for "n" should be small, compared to say, "m" and "k". So, if I'm searching for [mein] "main", it would match the letter sequence [meim] "maim" with, say, cost 0.1, whereas it would match the letter sequence [meik] "make" with, say, cost 0.7. Similarly, there are differing costs for inserting or deleting each letter. I can supply a confusion matrix that, for each letter pair (x,y), gives the cost of substituting x with y, where x and y are any letter or the empty string. I know that there are tools available that do approximate matching such as agrep, but as far as I can tell, they do not take a confusion matrix as input. That is, the cost of any insertion/substitution/deletion = 1. My question is, are there any open-source tools already available that can do approximate matching with confusion matrices, and if not, what is a good algorithm that I can implement to accomplish this?

    Read the article

  • ASP.NET MVC Map String Url To A Route Value Object

    - by mwgriffiths
    I am creating a modular ASP.NET MVC application using areas. In short, I have created a greedy route that captures all routes beginning with {application}/{*catchAll}. Here is the action: // get /application/index public ActionResult Index(string application, object catchAll) { // forward to partial request to return partial view ViewData["partialRequest"] = new PartialRequest(catchAll); // this gets called in the view page and uses a partial request class to return a partial view } Example: The Url "/Application/Accounts/LogOn" will then cause the Index action to pass "/Accounts/LogOn" into the PartialRequest, but as a string value. // partial request constructor public PartialRequest(object routeValues) { RouteValueDictionary = new RouteValueDictionary(routeValues); } In this case, the route value dictionary will not return any values for the routeData, whereas if I specify a route in the Index Action: ViewData["partialRequest"] = new PartialRequest(new { controller = "accounts", action = "logon" }); It works, and the routeData values contains a "controller" key and an "action" key; whereas before, the keys are empty, and therefore the rest of the class wont work. So my question is, how can I convert the "/Accounts/LogOn" in the catchAll to "new { controller = "accounts", action = "logon" }"?? If this is not clear, I will explain more! :) Matt This is the "closest" I have got, but it obviously wont work for complex routes: // split values into array var routeParts = catchAll.ToString().Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); // feels like a hack catchAll = new { controller = routeParts[0], action = routeParts[1] };

    Read the article

  • SQL select row into a string variable without knowing columns

    - by Brandi
    Hello, I am new to writing SQL and would greatly appreciate help on this problem. :) I am trying to select an entire row into a string, preferably separated by a space or a comma. I would like to accomplish this in a generic way, without having to know specifics about the columns in the tables. What I would love to do is this: DECLARE @MyStringVar NVARCHAR(MAX) = '' @MyStringVar = SELECT * FROM MyTable WHERE ID = @ID AS STRING But what I ended up doing was this: DECLARE @MyStringVar = '' DECLARE @SecificField1 INT DECLARE @SpecificField2 NVARCHAR(255) DECLARE @SpecificField3 NVARCHAR(1000) ... SELECT @SpecificField1 = Field1, @SpecificField2 = Field2, @SpecificField3 = Field3 FROM MyTable WHERE ID = @ID SELECT @StringBuilder = @StringBuilder + CONVERT(nvarchar(10), @Field1) + ' ' + @Field2 + ' ' + @Field3 Yuck. :( I have seen some people post stuff about the COALESCE function, but again, I haven't seen anyone use it without specific column names. Also, I was thinking, perhaps there is a way to use the column names dynamically getting them by: SELECT [COLUMN_NAME] FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'MyTable' It really doesn't seem like this should be so complicated. :( What I did works for now, but thanks ahead of time to anyone who can point me to a better solution. :) EDIT: Got it fixed, thanks to everyone who answered. :)

    Read the article

  • Truncating a string while storing it in an array in c

    - by Nick
    I am trying to create an array of 20 character strings with a maximum of 17 characters that are obtained from a file named "words.dat". After that the program should truncate the string only showing the first 17 characters and completely ignore the rest of that string. However My question is: I am not quite sure how to accomplish this, can anyone give me some insight on how to accomplish this task? Here is my current code as is: #include <stdio.h> #include <stdlib.h> #define WORDS 20 #define LENGTH 18 char function1(char[WORDS][LENGTH]); int main( void ) { char word_array [WORDS] [LENGTH]; function1(word_array); return ( 0 ) ; } char function1(char word_array[WORDS][LENGTH]) { FILE *wordsfile = fopen("words.dat", "r"); int i = 0; if (wordsfile == NULL) printf("\nwords.dat was not properly opened.\n"); else { for (i = 0; i < WORDS; i++) { fscanf(wordsfile, "%17s", word_array[i]); printf ("%s \n", word_array[i]); } fclose(wordsfile); } return (word_array[WORDS][LENGTH]); } words.dat file: Ninja DragonsFury failninja dragonsrage leagueoflegendssurfgthyjnu white black red green yellow green leagueoflegendssughjkuj dragonsfury Sword sodas tiger snakes Swords Snakes sage Sample output: blahblah@fang:~>a.out Ninja DragonsFury failninja dragonsrage leagueoflegendssu rfgthyjnu white black red green yellow green leagueoflegendssu ghjkuj dragonsfury Sword sodas tiger snakes Swords blahblah@fang:~> What will be accomplished afterwards with this program is: After function1 works properly I will then create a second function name "function2" that will look throughout the array for matching pairs of words that match "EXACTLY" including case . After I will create a third function that displays the 20 character strings from the words.dat file that I previously created and the matching words.

    Read the article

  • PHP: Extract direct sub directory from path string

    - by Nebs
    I need to extract the name of the direct sub directory from a full path string. For example, say we have: $str = "dir1/dir2/dir3/dir4/filename.ext"; $dir = "dir1/dir2"; Then the name of the sub-directory in the $str path relative to $dir would be "dir3". Note that $dir never has '/' at the ends. So the function should be: $subdir = getsubdir($str,$dir); echo $subdir; // Outputs "dir3" If $dir="dir1" then the output would be "dir2". If $dir="dir1/dir2/dir3/dir4" then the output would be "" (empty). If $dir="" then the output would be "dir1". Etc.. Currently this is what I have, and it works (as far as I've tested it). I'm just wondering if there's a simpler way since I find I'm using a lot of string functions. Maybe there's some magic regexp to do this in one line? (I'm not too good with regexp unfortunately). function getsubdir($str,$dir) { // Remove the filename $str = dirname($str); // Remove the $dir if(!empty($dir)){ $str = str_replace($dir,"",$str); } // Remove the leading '/' if there is one $si = stripos($str,"/"); if($si == 0){ $str = substr($str,1); } // Remove everything after the subdir (if there is anything) $lastpart = strchr($str,"/"); $str = str_replace($lastpart,"",$str); return $str; } As you can see, it's a little hacky in order to handle some odd cases (no '/' in input, empty input, etc). I hope all that made sense. Any help/suggestions are welcome.

    Read the article

  • C# Linq to SQL connection string (newbie)

    - by Chris'o
    i am a new linq to sql learner and this is my very first attempt to create a data viewer program. The idea is simple, i'd like to create a software that is able to view content of a table in a database. That's it. I got an early problem here already and i have seen many tutes and articles online but I still cant fix the bug. Here is my code: static void Main(string[] args) { string cs = "Data Source=localhost;Initial Catalog=somedb;Integrated Security=SSPI;"; var db = new DataClasses1DataContext(cs); db.Connection.Open(); foreach (var b in db.Mapping.GetTables()) Console.WriteLine(b.TableName); Console.ReadKey(true); } When I tried to check db.connection.equals(null); it returns false, so i thought i have connected successfully to the database since there is no error at all. But the code above doesn't print anything out to the screen. I kind of lost and don't know what's going on here. Does anyone know what is going wrong here?

    Read the article

  • If statement String trouble

    - by Jeremy Stone
    I'm trying to create a program which takes user input of two words and determines whether or not these words are the same. import java.util.Scanner; public class L7E3 { public static void main(String[] args) { Scanner keyboard = new Scanner(System. in ); String word1, word2; System.out.println("Please enter a word: "); word1 = keyboard.nextLine(); System.out.println("Please enter a word: "); word2 = keyboard.nextLine(); if (word1 == word2) { System.out.println("The words are " + word1 + " and " + word2 + ". These words are the same."); } else { System.out.println("The words are " + word1 + " and " + word2 + ". These words are not the same."); } } } I figured that word1==word2 would have worked to determine whether the two strings were equal, I'm using JGrasp and it goes directly to my else option regardless of input. Am I doing something wrong with strings?

    Read the article

  • How to create a String Array and link it to a Grade array

    - by user1861544
    I have a project that I need to create 2 Arrays, one to hold Student Names and one to hold Student Scores. The user inputs the size of the array, and the array needs to be sorted using BubbleSort (putting the high scores at the top). I have started the project, created the first array for scores, I have successfully done bubble sort and sorted the grades. Now I can't figure out how to make an array for Names, and once I do how do I make the names array correspond to the Grades array BubbleSort? Here is the code I have so far. import java.util.Scanner; public class Grades { public static void main(String[]args){ { Scanner UserIn = new Scanner(System.in); System.out.print( "How many students are there? " ); int[]GradeArray = new int[UserIn.nextInt()]; for( int i=0 ; i<GradeArray.length ; i++ ) { System.out.print( "Enter Grade for Student " + (i+1) + ": " ); GradeArray[i] = UserIn.nextInt(); } bubbleSort(GradeArray); for( int i : GradeArray ) System.out.println( i ); System.out.println(); } } private static void bubbleSort(int[]GradeArray){ int n = GradeArray.length; int temp = 0; String temp2; for(int i=0; i<n; i++){ for(int j=1; j<(n-i);j++){ if(GradeArray[j-1]<GradeArray[j]){ //swap temp=GradeArray[j-1]; GradeArray[j-1]=GradeArray[j]; GradeArray[j]=temp; } } } } } Also how do I change the grades to Double? I started with Int and when I try to change everything to double I get an error saying "Found Double, expected Int".

    Read the article

  • split a string into a key => value array in php

    - by andy-score
    +2-1+18*+7-21+3*-4-5+6x29 The above string is an example of the kind of string I'm trying to split into either a key = value array or something similar. The numbers represent the id of a class and -,+ and x represent the state of the class (minimised, expanded or hidden), the * represents a column break. I can split this into the columns easily using explode which gives and array with 3 $key = $value associations. eg. $column_layout = array( [0] => '+2-1+18' , [1] => '+7-21+3' , [2] => '-4-5+6x29' ) I then need to split this into the various classes from there, keeping the status and id together. eg. $column1 = array( '+' => 2 , '-' => 1 , '+' => 18 ) ... or $column1 = array( array( '+' , 2 ) , array( '-' , 1 ) , array( '+' , 18 ) ) ... I can't quite get my head round this and what the best way to do it is, so any help would be much appreciated.

    Read the article

  • jquery post work with hebrew (unicode) but not with spaces, get not working with hebrew but does spa

    - by Y.G.J
    i have tried load and hebrew didn't work for me so i changed my code to $.ajax({ type: "post", url: "process-tb.asp", data: data, success: function(msg) (partial code) not knowing that post and get is the problem for my hebrew querystring. so know i can get my page to get the hebrew and english but no spaces are add to the text. all pages are encoded to utf-8. what is wrong with it?

    Read the article

  • How to use unicode inside an xpath string? (UnicodeEncodeError)

    - by Gj
    I'm using xpath in Selenium RC via the Python api. I need to click an a element who's text is "Submit »" Here's the error that I'm getting: In [18]: sel.click(u"xpath=//a[text()='Submit \xbb')]") ERROR: An unexpected error occurred while tokenizing input The following traceback may be corrupted or invalid The error message is: ('EOF in multi-line statement', (1121, 0)) --------------------------------------------------------------------------- Exception Traceback (most recent call last) /Users/me/<ipython console> in <module>() /Users/me/selenium.pyc in click(self, locator) 282 'locator' is an element locator 283 """ --> 284 self.do_command("click", [locator,]) 285 286 /Users/me/selenium.pyc in do_command(self, verb, args) 213 #print "Selenium Result: " + repr(data) + "\n\n" 214 if (not data.startswith('OK')): --> 215 raise Exception, data 216 return data 217 <type 'str'>: (<type 'exceptions.UnicodeEncodeError'>, UnicodeEncodeError('ascii', u"ERROR: Invalid xpath [2]: //a[text()='Submit \xbb')]", 45, 46, 'ordinal not in range(128)'))

    Read the article

< Previous Page | 41 42 43 44 45 46 47 48 49 50 51 52  | Next Page >