Search Results

Search found 35302 results on 1413 pages for 'string literals'.

Page 86/1413 | < Previous Page | 82 83 84 85 86 87 88 89 90 91 92 93  | Next Page >

  • Binding a date string parameter in an MS Access PDO query

    - by harryg
    I've made a PDO database class which I use to run queries on an MS Access database. When querying using a date condition, as is common in SQL, dates are passed as a string. Access usually expects the date to be surrounded in hashes however. E.g. SELECT transactions.amount FROM transactions WHERE transactions.date = #2013-05-25#; If I where to run this query using PDO I might do the following. //instatiate pdo connection etc... resulting in a $db object $stmt = $db->prepare('SELECT transactions.amount FROM transactions WHERE transactions.date = #:mydate#;'); //prepare the query $stmt->bindValue('mydate', '2013-05-25', PDO::PARAM_STR); //bind the date as a string $stmt->execute(); //run it $result = $stmt->fetch(); //get the results As far as my understanding goes the statement that results from the above would look like this as binding a string results in it being surrounded by quotes: SELECT transactions.amount FROM transactions WHERE transactions.date = #'2013-05-25'#; This causes an error and prevents the statement from running. What's the best way to bind a date string in PDO without causing this error? I'm currently resorting to sprintf-ing the string which I'm sure is bad practise. Edit: if I pass the hash-surrounded date then I still get the error as below: Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[22018]: Invalid character value for cast specification: -3030 [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression. (SQLExecute[-3030] at ext\pdo_odbc\odbc_stmt.c:254)' in C:\xampp\htdocs\ips\php\classes.php:49 Stack trace: #0 C:\xampp\htdocs\ips\php\classes.php(49): PDOStatement-execute() #1 C:\xampp\htdocs\ips\php\classes.php(52): database-execute() #2 C:\xampp\htdocs\ips\try2.php(12): database-resultset() #3 {main} thrown in C:\xampp\htdocs\ips\php\classes.php on line 49

    Read the article

  • format the ouput of a string

    - by prince23
    hi here string strTrendScore="2"; or string strTrendScore="2.45656" now here i am checking the condition if it is double value = double.Parse(strTrendScore); strTrendScore = value.ToString("##.##"); 2.45656 like this then i am showing the output as 2.45 if the input is string strTrendScore="2"; then the ouput is shown as "2" but now i need to show the output has 2.00 how can i format the code like this based on the condition

    Read the article

  • Use LINQ and lambdas to put string in proper case

    - by Tobias Funke
    I have this function called ProperCase that takes a string, then converts the first letter in each word to uppercase. So ProperCase("john smith") will return "John Smith". Here is the code: public string ProperCase(string input) { var retVal = string.Empty; var words = input.Split(' '); foreach (var word in words) { if (word.Length == 1) { retVal += word.ToUpper(); } else if (word.Length > 1) { retVal += word.Substring(0, 1).ToUpper() + word.Substring(1).ToLower(); } retVal += ' '; } if (retVal.Length > 0) { retVal = retVal.Substring(0, retVal.Length - 1); } return retVal; } This code workds perfectly, but I'm pretty sure I can do it more elegantly with LINQ and lambdas. Can some please show me how?

    Read the article

  • string.Replace does not work for quote

    - by Azhar
    ((string)dt.Rows[i][1]).Replace("'", "\'") I want the result that if any string have quote it change it into slash quote e.g John's - John\'s but the above replace function is not working fine. it results like John\'s but if we change the code to ((string)dt.Rows[i][1]).Replace("'", "\'") it gives the Result like John's does change it anyway.

    Read the article

  • Using generics to make an algorithm work on lists of "something" instead of only String's

    - by Binary255
    Hi, I have a small algorithm which replaces the position of characters in a String: class Program { static void Main(string[] args) { String pairSwitchedStr = pairSwitch("some short sentence"); Console.WriteLine(pairSwitchedStr); Console.ReadKey(); } private static String pairSwitch(String str) { StringBuilder pairSwitchedStringBuilder = new StringBuilder(); for (int position = 0; position + 1 < str.Length; position += 2) { pairSwitchedStringBuilder.Append((char)str[position + 1]); pairSwitchedStringBuilder.Append((char)str[position]); } return pairSwitchedStringBuilder.ToString(); } } I would like to make it as generic as possible, possibly using Generics. What I'd like to have is something which works with: Anything that is built up using a list of instances. Including strings, arrays, linked lists I suspect that the solution must use generics as the algorithm is working on a list of instances of T (there T is ... something). Version of C# isn't of interest, I guess the solution will be nicer if features from C# version 2.0 is used.

    Read the article

  • Render view as string then redirect.

    - by JohnRudolfLewis
    In my ASP.NET MVC application, I would like my controller action to render a view to a string, send an email using that string as the body, then do a redirect. I've found several articles here on SO and elsewhere on how to render the view to a string. That part was easy. But when I attempt to perform the redirect, I get an HttpException: Cannot redirect after HTTP headers have been sent. I've tried setting Response.Buffer and Response.BufferOutput to true, I've tried Response.Clear, nothing seems to work. Is it possible to render a view to a string, then do a redirect?

    Read the article

  • how to call sql string from nhibernate

    - by frosty
    i have the following method, at the moment it's return the whole sql string. How would i execute the following. using (ITransaction transaction = session.BeginTransaction()) { string sql = string.Format( @"DECLARE @Cost money SET @Cost = -1 select @Cost = MAX(Cost) from item_costings where Item_ID = {0} and {1} >= Qty1 and {1} <= Qty2 RETURN (@Cost)", itemId, quantity); string mystring = session .CreateSQLQuery(sql) .ToString(); transaction.Commit(); return mystring; } // EDIT here is the final version using criteria using (ISession session = NHibernateHelper.OpenSession()) { decimal cost = session .CreateCriteria(typeof (ItemCosting)) .SetProjection(Projections.Max("Cost")) .Add(Restrictions.Eq("ItemId", itemId)) .Add(Restrictions.Le("Qty1", quantity)) .Add(Restrictions.Ge("Qty2", quantity)) .UniqueResult<decimal>(); return cost; }

    Read the article

  • String to datetime

    - by SARAVAN
    I have a string 12012009 input by the user in ASP.NET MVC application. I wanted to convert this to a DateTime. But if I do DateTime.TryParse("12012009", out outDateTime); it returns a false. So I tried to convert 12012009 to 12/01/2009 and then do DateTime.TryParse("12/01/2009", out outDateTime); which will work But I don't find any straight forward method to convert string 12012009 to string "12/01/2009". Any ideas?

    Read the article

  • Write a function that returns the longest palindrome in a given string. e.g "ccddcc" in the string "

    - by Learner
    I thought of a solution but it runs in O(n^2) time Algo 1: Steps: Its a brute force method Have 2 for loops for i = 1 to i less than array.length -1 for j=i+1 to j less than array.length This way you can get substring of every possible combination from the array Have a palindrome function which checks if a string is palindrome so for every substring (i,j) call this function, if it is a palindrome store it in a string variable If you find next palindrome substring and if it is greater than the current one, replace it with current one. Finally your string variable will have the answer Issues: 1. This algo runs in O(n^2) time. Algo 2: Reverse the string and store it in diferent array Now find the largest matching substring between both the array But this too runs in O(n^2) time Can you guys think of an algo which runs in a better time. If possible O(n) time

    Read the article

  • get particular string using regex java

    - by hussain
    i want to know how to get the string from group of string String j = "<a href=\"/watch?v=4Qx-lBqOqiQ&feature=popular\" onclick=\"\" onmousedown=\"yt.analytics.urchinTracker(\'/Events/Home/PersonalizedHome/POP/Logged_Out');\" ><span class=\"video-thumb video-thumb-220 \" id=\"video-thumb-4Qx-lBqOqiQ-8821469\"><img src=\"http://i1.ytimg.com/vi/4Qx-lBqOqiQ/hqdefault.jpg\" class=\"vimg220\" alt=\"Dog Squirrel Chasing A Squirrel\" title=\"Dog Squirrel Chasing A Squirrel\" onclick=\";yt.www.watch.watch5.IEshenanigans(event, this)\"><span class=\"video-time\"><span>1:08</span></span><span class=\"video-actions\"><button class=\"yt-uix-button-short yt-uix-button yt-uix-button-arrowbutton\" onclick=\"; return false;\" type=\"button\"> <img class=\"yt-uix-button-arrow\" src=\"http://s.ytimg.com/yt/img/pixel-vfl73.gif\" alt=\"\"> hai</a>"; i want to get the string href=\"/watch?v=4Qx-lBqOqiQ&feature=popular\" and src=\"http://i1.ytimg.com/vi/4Qx-lBqOqiQ/hqdefault.jpg\" thanks and advance

    Read the article

  • Having issue Deserializing array from an XML string

    - by LeeHull
    I'm having issues trying to deserializing my xml string that was from a dataset.. Here is the XML layout.. <DataSet> <User> <UserName>Test</UserName> <Email>[email protected]</Email> <Details> <ID>1</ID> <Name>TestDetails</Name> <Value>1</Value> </Details <Details> <ID>2</ID> <Name>Testing</Name> <Value>3</Value> </Details </User> </DataSet> Now I am able to deserialize the "UserName" and "Email" when doing public class User { public string UserName {get;set;} public string Email {get;set;} public Details[] Details {get;set;} } public class Details { public int ID {get;set;} public string Name {get;set;} public string Value {get;set;} } This deserializes fine when I just get the user node, the Details isnt null but has no items in it.. i know I am suppose to have between all the details but I rather not modify the XML, anyways to get this to deserialize properly without recreating the XML after I get it?

    Read the article

  • Search a variable for an address

    - by chrissygormley
    Hello, I am trying to match information stored in a variable. I have a list of uuid's and ip addresses beside them. The code I have is: r = re.compile(r'urn:uuid:5EEF382F-JSQ9-3c45-D5E0-K15X8M8K76') m = r.match(str(serv)) if m1: print'Found' The string serv contains is: urn:uuid:7FDS890A-KD9E-3h53-G7E8-BHJSD6789D:[u'http://10.10.10.20:12365/7FDS890A-KD9E-3h53-G7E8-BHJSD6789D/'] --------------------------------------------- urn:uuid:5EEF382F-JSQ9-3c45-D5E0-K15X8M8K76:[u'http://10.10.10.10:42365'] --------------------------------------------- urn:uuid:8DSGF89S-FS90-5c87-K3DF-SDFU890US9:[u'http://10.10.10.40:5234'] --------------------------------------------- So basically I am wanting to find the uuid string and find out what it's address is and store it as a variable. So far I have just tried to get it to match the string to no avail. Can anyone point out a solution to this. Thanks

    Read the article

  • How to covert UTF8 string to UTF16 in JNI

    - by Er Rahul Rajkumar Gupta
    Can anyone please tell me that what is going on wrong with me in this code.Actually in following line of codes I am taking the path of sdcard in a string in jni (C code) and in concatenate function concatenating these manually using loop.The string returned by concatenate works fine but when I am converting it to jstring it prints garbage value in my logcat. Kindly tell me what is the problem. jstring str=(jstring)env->CallObjectMethod(sdcard,storagestring); const char jclass cfile=env->FindClass("java/io/File"); jmethodID fileid=env->GetMethodID(cfile,"<init>","(Ljava/lang/String;)V"); jclass envir=env->FindClass("android/os/Environment"); jmethodID storageid=env->GetStaticMethodID(envir,"getExternalStorageDirectory","()Ljava/io/File;"); jobject sdcard=env->CallStaticObjectMethod(envir,storageid); jclass sdc=env->GetObjectClass(sdcard); jmethodID storagestring=env->GetMethodID(sdc,"toString","()Ljava/lang/String;"); *nativeString = env->GetStringUTFChars(str, 0); char *s =concatenate(nativeString,"/f1.3gp"); //fpath=s; fpath=env->NewStringUTF(s); jobject fobject=env->NewObject(cfile,fileid,fpath); LOGI("size of char=%d size of string=%d",sizeof("/f1.3gp"),sizeof(fpath)); jmethodID existid=env->GetMethodID(cfile,"exists","()Z"); if(env->CallBooleanMethod(fobject,existid)) { jmethodID delid=env->GetMethodID(cfile,"delete","()Z"); if(env->CallBooleanMethod(fobject,delid)) LOGE("File is deleting...%s",env->NewStringUTF("/f1.3gp")); } jmethodID newfileid=env->GetMethodID(cfile,"createNewFile","()Z"); if(env->CallBooleanMethod(fobject,newfileid)) LOGE("dig dig %s",fpath); jthrowable exc=env->ExceptionOccurred(); if(exc) { env->ExceptionDescribe(); env->ExceptionClear(); } LOGE("creating file %s",fpath); }

    Read the article

  • regex split and extract multiple parts from a string

    - by nLL
    I am trying to extract some parts of the "Video:" line from below text. Seems stream 0 codec frame rate differs from container frame rate: 30000.00 (300 00/1) -> 14.93 (1000/67) Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'C:\a.3gp': Metadata: major_brand : 3gp5 minor_version : 0 compatible_brands: 3gp5isom Duration: 00:00:45.82, start: 0.000000, bitrate: 357 kb/s Stream #0.0(und): Video: mpeg4, yuv420p, 352x276 [PAR 1:1 DAR 88:69], 344 kb /s, 14.93 fps, 14.93 tbr, 90k tbn, 30k tbc Stream #0.1(und): Audio: aac, 16000 Hz, mono, s16, 11 kb/s Stream #0.2(und): Data: mp4s / 0x7334706D, 0 kb/s Stream #0.3(und): Data: mp4s / 0x7334706D, 0 kb/s* This is an output from ffmpeg command line where i can get Video: part with private string ExtractVideoFormat(string rawInfo) { string v = string.Empty; Regex re = new Regex("[V|v]ideo:.*", RegexOptions.Compiled); Match m = re.Match(rawInfo); if (m.Success) { v = m.Value; } return v; } and result is mpeg4, yuv420p, 352x276 [PAR 1:1 DAR 88:69], 344 kb What i am trying to do is to somehow split that line and get mpeg4 yuv420p 352x276 [PAR 1:1 DAR 88:69] 344 kb assigned to different string objects instead of single

    Read the article

  • unterminated string literal on json eval

    - by sonam
    I am trying to eval() a json having speacial characters - 
 and getting "unterminated string literal" error in Firefox 3.5.9 Although the same works fine on IE. 7. I have set the character encoding to UTF-8 in both the browsers. Any idea why its an error in FF? Also right before converting the String to JSON, I ran this code in java String jsonString = //some json string having 
 for(byte b : jsonString.getBytes()){ System.out.print(Integer.toHexString(b) + " "); } net.sf.json.JSON jsonObject = net.sf.json.JSONSerializer.toJSON(jsonString); And the o/p for above characters is ffffffe2 ffffff80 ffffffa8 respectively. How do I know if these are valid UTF-8 characters?

    Read the article

  • How to convert from hex-encoded string to a "human readable" string?

    - by John Jensen
    I'm using the Net-SNMP bindings for python and I'm attempting to grab an ARP cache from a Brocade switch. Here's what my code looks like: #!/usr/bin/env python import netsnmp def get_arp(): oid = netsnmp.VarList(netsnmp.Varbind('ipNetToMediaPhysAddress')) res = netsnmp.snmpwalk(oid, Version=2, DestHost='10.0.1.243', Community='public') return res arp_table = get_arp() print arp_table The SNMP code itself is working fine. Output from snmpwalk looks like this: <snip> IP-MIB::ipNetToMediaPhysAddress.128.10.200.6.158 = STRING: 0:1b:ed:a3:ec:c1 IP-MIB::ipNetToMediaPhysAddress.129.10.200.6.162 = STRING: 0:1b:ed:a4:ac:c1 IP-MIB::ipNetToMediaPhysAddress.130.10.200.6.166 = STRING: 0:1b:ed:38:24:1 IP-MIB::ipNetToMediaPhysAddress.131.10.200.6.170 = STRING: 74:8e:f8:62:84:1 </snip> But my output from the python script yields a tuple of hex-encoded strings that looks like this: ('\x00$8C\x98\xc1', '\x00\x1b\xed;_A', '\x00\x1b\xed\xb4\x8f\x81', '\x00$86\x15\x81', '\x00$8C\x98\x81', '\x00\x1b\xed\x9f\xadA', ...etc) I've spent some time googling and came across the struct module and the .decode("hex") string method, but the .decode("hex") method doesn't seem to work: Python 2.7.3 (default, Apr 10 2013, 06:20:15) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> hexstring = '\x00$8C\x98\xc1' >>> newstring = hexstring.decode("hex") Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.7/encodings/hex_codec.py", line 42, in hex_decode output = binascii.a2b_hex(input) TypeError: Non-hexadecimal digit found >>> And the documentation for struct is a bit over my head.

    Read the article

  • Create class instance in assembly from string name

    - by Arcadian
    I'm not sure if this is possible, and I'm quite new to using assemblies in C#.NET. What I would like to do is to create an instance of a class when supplied the string name of that class. Something like this: using MyAssembly; namespace MyNameSpace { Class MyClass { int MyValue1; int MyValue2; public MyClass(string myTypeName) { foreach(Type type in MyAssembly) { if((string)type == myTypeName) { //create a new instance of the type } } AssignInitialValues(//the type created above) } //Here I use an abstract type which the type above inherits from private void AssignInitialValues(AbstractType myClass) { this.value1 = myClass.value1; this.value2 = myClass.value2; } } } Obviously you cannot compare strings to types but it illustrates what I'm trying to do: create a type from a supplied string. Any thoughts? EDIT: After attempting: var myObject = (AbstractType) Activator.CreateInstance(null, myTypeName); AssignInitialValues(myObject); I get a number of errors: Inconsistent accessibility: parameter type 'MyAssembly.AbstractType' is less accessible than method 'MyNameSpace.MyClass.AssignInitialValues(MyAssembly.AstractType)' 'MyAssembly.AstractType' is inaccessible due to it's protection level The type or namespace name 'MyAssembly' could not be found (are you missing a using directive or an assembly reference?) The type or namespace name 'AbstractType' could not be found (are you missing a using directive or an assembly reference?) Not exactly sure why it can't find the assembly; I've added a reference to the assembly and I use a Using Directive for the namespace in the assembly. As for the protection level, it's calling classes (or rather the constructors of classes) which can only be public. Any clues on where the problem is? UPDATE: After looking through several articles on SO I came across this: http://stackoverflow.com/a/1632609/360627 Making the AbstractTypeclass public solved the issue of inconsistent accessibility. The new compiler error is this: Cannot convert type 'System.Runtime.Remoting.ObjectHandle' to 'MyAssembly.AbstractType' The line it references is this one: var myObject = (AbstractType) Activator.CreateInstance(null, myTypeName); Using .Unwrap() get's me past this error and I think it's the right way to do it (uncertain). However, when running the program I then get a TypeLoadException when this code is called. TypeLoadException: Could not load type ‘AbstractType’ from assembly ‘MyNameSpace'... Right away I can spot that the type its looking for is correct but the assembly it's looking in is wrong. Looking up the Activator.CreateInstance(String, String) method revealed that the null as the first argument means that the method will look in the executing assembly. This is contrary to the required behavior as in the original post. I've tried using MyAssembly as the first argument but this produces the error: 'MyAssembly' is a 'namespace' but is used like a 'variable' Any thoughts on how to fix this?

    Read the article

  • Doctrine: String keys with Array hydration

    - by BenV
    According to their documentation, you should use Array hydration rather than record hydration when retrieving data for read-only purposes. However, this means I have to access the attributes of the retrieved object using arrays and string keys: $user['Phonenumbers'][0]['number'] instead of the OO style: $user->PhoneNumbers[0]->number Now I'm kinda new to PHP, but in other languages I've worked with the 2nd notation would be preferable because typos would be caught at compile time while typos in string literals would not be noticed until runtime. Does this apply to PHP/Doctrine?

    Read the article

  • String tokenizer for PHP

    - by Jack
    I have used the String Tokenizer in Java. I wish to know if there is similar functionality for PHP. I have a string and I want to extract individual words from it. eg. If the string is - Summer is doubtful #haiku #poetry #babel I want to know if it contains the hashtag #haiku.

    Read the article

< Previous Page | 82 83 84 85 86 87 88 89 90 91 92 93  | Next Page >