Search Results

Search found 2155 results on 87 pages for 'mathematical expressions'.

Page 61/87 | < Previous Page | 57 58 59 60 61 62 63 64 65 66 67 68  | Next Page >

  • Use 'let' in 'if' expression

    - by demas
    I need a function that works like this: foo :: Integer -> Integer -> [Integer] foo a b = do let result = [] let Coord x y = boo a b if x > 0 let result = result ++ [3] if y > 0 let result = result ++ [5] if x < a let result = result ++ [7] if y < b let result = result ++ [9] result I can not use the guards because the result can have more then one element. But as I see I can not use 'let' in the 'if' expression: all_possible_combinations.hs:41:14: parse error on input `let' How can I check multiple expressions and add new elements in the list? I search not only imperative solution, but the functional one.

    Read the article

  • Java Counting # of occurrences of a word in a string

    - by Doug
    I have a large text file I am reading from and I need to find out how many times some words come up. For example, the word "the". I'm doing this line by line each line is a string. I need to make sure that I only count legit "the"'s the the in other would not count. This means I know I need to use regular expressions in some way. What I was trying so far is this: numSpace += line.split("[^a-z]the[^a-z]").length; I realize the regular expression may not be correct at the moment but I tried without that and just tried to find occurrences of the word the and I get wrong numbers to. I was under the impression this would split the string up into an array and how many times that array was split up was how many times the word is in the string. Any ideas I would be grateful.

    Read the article

  • [Android] How do I load URL that requires login into variable?

    - by bebeTech
    I am trying to port my usage meter from a JavaScript Gadget (win) / Widget (OSX) to Android. Total newbie when comes to JAVA + Eclipse + Android 2.1 SDK. Essentially what I want to do is load a page, pass through a username and password and load the resulting page into a array that I can then run some regular expressions through. My code from JavaScript (I've replace the actual URL with a dummy one) is: xmlhttp.open("post","https://acme.com.au/your_account/index.php?function=login",false); xmlhttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT"); xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xmlhttp.send("check_username=" + username + "&password=" + password); I need to know the Android equivalent to the above please. I've played around with WebView but that loads the page in a web browser which isn't what I want.

    Read the article

  • Trouble compiling some decompiled C# code

    - by Colin O'Dell
    I was decompiling an open-source project (because the source for the latest version hasn't been released yet). Using RedGate's Reflector tool, it gave me this block of code: if(somecondition == true) { ref Vector3i vectoriRef; float num17 = length - num; Vector3i end = vectori3; (vectoriRef = (Vector3i) &end)[1] = vectoriRef[1] - ((int) num17); } somecondition is a boolean. length and num are floats defined outside the code. vectori3 is also defined outside the code and is of type Vector3i. The type Vector3i is essentially this code, but with x, y, and z stored as integers. When I try to compile this decompiled code, I get the following errors: Line 2: Only assignment, call, increment, decrement, and new object expressions can be used as a statement Line 3: ; expected Line 3: Invalid expression term 'ref' Line 6: 'Vector3i' is a 'type' but is used like a 'variable' Any thoughts on how I can fix this code so it compiles correctly and does whatever it was intended to do?

    Read the article

  • Extracting property names from a c# source file

    - by Pete
    I want to parse a c# file. The only thing I want is to determine if it contains a property with a specific name; just a simple true/false response. Or rather, since I'd checking for more than one property in each run, extracting a list of property names could be helpful I thought that I could create an elegant solution using the CodeDomProvider functionality (f# example): use reader = new StreamReader(existingFile) let codeProvider = new CSharpCodeProvider() let codeUnit = codeProvider.Parse(reader) Unfortunately, the Parse function is not implemented for the CSharpCodeProvider. Is there a way to get a CodeCompileUnit from a source file? Or is there another elegant way? (I had hoped to avoid regular expressions on this)?

    Read the article

  • Best approch to dynamically filter .net objects

    - by maxba
    The project i´m working currently on has a way to define a filter to filter objects from a database. This filter is a pretty straitforward class containing filtercriteria that will be combined to a sql where-clause. The goal now is to use this filter class to filter .net objects as well. So the filter for example defines, that the title property of the object that it is applied to must contain some userdefined string etc. What are ways to approch this problem? What should the filter return instead of the sql where-clause and how can it be applied to the object? I´m thinking about this for hours and don´t yet have even a slight idea how to solve this. Been thinking about reflection, dynamic code execution, building expressions but still haven´t found an acutal starting point.

    Read the article

  • Python __setattr__ and __getattr__ for global scope?

    - by KT
    Suppose I need to create my own small DSL that would use Python to describe a certain data structure. E.g. I'd like to be able to write something like f(x) = some_stuff(a,b,c) and have Python, instead of complaining about undeclared identifiers or attempting to invoke the function some_stuff, convert it to a literal expression for my further convenience. It is possible to get a reasonable approximation to this by creating a class with properly redefined __getattr__ and __setattr__ methods and use it as follows: e = Expression() e.f[e.x] = e.some_stuff(e.a, e.b, e.c) It would be cool though, if it were possible to get rid of the annoying "e." prefixes and maybe even avoid the use of []. So I was wondering, is it possible to somehow temporarily "redefine" global name lookups and assignments? On a related note, maybe there are good packages for easily achieving such "quoting" functionality for Python expressions?

    Read the article

  • Doxygen C++ comment string parser in python?

    - by Sebastian
    Does anybody know of a python module to parse a doxygen style C++ comment string? I mean a string like this (simple example): /** * A constructor. * A more elaborate description of the constructor. * @param param1 test1 * @param param2 test2 */ and I would like to extract the brief, the long description, the parameters, the return value etc. I'm currently doing this using string methods and regular expressions but my solution is not very robust. Alternatively can anybody recommend an easy to use python parser lib that I can set up quickly? Thanks in advance

    Read the article

  • Regex expression with leading zero

    - by user1874087
    I'm rather new to regex expressions and need help with a simple expression. I'm using Pentaho for ETL (Replace in String transformation) and I have column values that I need to add leading zeros to and parse out text as part of the database import. So far I have been unable to add the leading zero. The column is called Region and the values are "region 8", "region 10", "region 11". My regex expression is ['Region'] which will eliminate the region text but produces results = "8", "10", "11". I need values to produce "08", "10", "11". So all the single digit numbers must have leading zeros.

    Read the article

  • Passing dependent objects to a parent constructor in Scala

    - by Nick Johnson
    Suppose I have the following class heirarchy: class A() class B(a:A) class C(b:B) class BaseClass(b:B, c:C) Now I want to implement a subclass of BaseClass, which is given an instance of A, and constructs instances of B and C, which it passes to its superclass constructor. If I could use arbitrary expressions, I'd do something like this: b = new B(a) c = new C(b) super(b, c) Because the second argument to the parent constructor depends on the value of the first argument, though, I can't see any way to do this, without using a factory function, or a gratuitous hack, such as : class IntermediateSubclass(b:B) extends BaseClass(b, new C(b)) class RealSubclass(a:A) extends IntermediateSubclass(new B(a)) Is there clean way to do this?

    Read the article

  • regular expression to check file content type is .doc or not?

    - by Pandiya Chendur
    When i use a file upload i use to check file contenttype with regular expressions... For ex private bool IsImage(HttpPostedFile file) { if (file != null && Regex.IsMatch(file.ContentType, "image/\\S+") && file.ContentLength > 0) { return true; } return false; } This returns my file is an image or not... How to check it is a word(.doc/.docx) document or not using c#...

    Read the article

  • C variable decleration on gcc compiler - compile time error.

    - by liv2hak
    Assume the following C variable decleration int *A[10] , B[10][10]; Of the following expressions A[2] A[2][3] B[1] B[2][3] which will not give compile time errors if used as left hand sides of assignment statements in a C program. A) 1,2 and 4 only B) 2,3, and 4 only C) 2 and 4 only D) 4 only I have tried this on a gcc compiler.I assigned the value '0' to all the above variables.Only the third one showed an error.I can't really understand the reason.Can someone please expalin why that is.? Thanks

    Read the article

  • how to add markup to text using JavaScript regex

    - by Richard
    I need to add markup to some text using JavaScript regular expressions. In Python I could do this with: >>> import re >>> re.sub('(banana|apple)', r'<b>{\1}</b>', 'I have 1 banana and 2 apples!') 'I have 1 <b>{banana}</b> and 2 <b>{apple}</b>s!' What is the equivalent in JavaScript? string.replace(regex, newstring) seems to only take a raw string for replacing.

    Read the article

  • One regular expression to match parts in various positions

    - by richsage
    Hi all, I'm trying to parse a DSN (from a Symfony application) using regular expressions, in order to link with a secondary application, but using the same database. The DSN I currently have is: mysql:dbname=my_db_name;host=localhost with a regex of: /^(\w+):(dbname=(\w+))?;?(host=(\w+))?/ (using preg_match()). This matches OK, but fails in my test environment because the DSN elements are switched around, thus: mysql:host=localhost;dbname=my_testdb_name I could just switch them round, yes :-) but I'm sure that extraction of the host and dbname parts from both DSNs is possible with a single regular expression, and I'd like to be able to enhance my knowledge at the same time ;-) Is there a way I can do this?

    Read the article

  • Problem when reading backslash in Prolog

    - by Jerry
    I'm writing a lexer in Prolog which will be used as a part of functional language interpreter. Language spec allows expressions like for example let \x = x + 2; to occur. What I want lexer to do for such input is to "return": [tokLet, tokLambda, tokVar(x), tokEq, tokVar(x), tokPlus, tokNumber(2), tokSColon] and the problem is, that Prolog seems to ignore the \ character and "returns" the line written above except for tokLambda. One approach to solve this would be to somehow add second backslash before/after every occurrence of one in the program code (because everything works fine if I change the original input to let \\x = x + 2;) but I don't really like it. Any ideas?

    Read the article

  • What is Perl's secret of getting small code do so much?

    - by sak
    I've seen many (code-golf) Perl programs out there and even if I can't read them (Don't know Perl) I wonder how you can manage to get such a small bit of code to do what would take 20 lines in some other programming language. What is the secret of Perl? Is there a special syntax that allows you to do complex tasks in few keystrokes? Is it the mix of regular expressions? I'd like to learn how to write powerful and yet short programs like the ones you know from the code-golf challenges here. What would be the best place to start out? I don't want to learn "clean" Perl - I want to write scripts even I don't understand anymore after a week. If there are other programming languages out there with which I can write even shorter code, please tell me.

    Read the article

  • String Functions in IIS Url Rewrite Module

    - by Nariman
    The IIS URL Rewrite Module ships with 3 built-in functions: * ToLower - returns the input string converted to lower case. * UrlEncode - returns the input string converted to URL-encoded format. This function can be used if the substitution URL in rewrite rule contains special characters (for example non-ASCII or URI-unsafe characters). * UrlDecode - decodes the URL-encoded input string. This function can be used to decode a condition input before matching it against a pattern. The functions can be invoked by using the following syntax: {function_name:any_string} The question is: can this list be extended by introducing a Replace function that's available for changing values within a rewrite rule action or condition? Another way to frame the question: is there any way to do a global replace on a URL coming in using this module? It seems that you're limited to using regular expressions and back-references to construct strings, without a search/replace functionality to replace every X with Y in {REQUEST_URI} before issuing a redirect.

    Read the article

  • Regular expression match, extracting only wanted segments of string

    - by Ben Carey
    I am trying to extract three segments from a string. As I am not particularly good with regular expressions, I think what I have done could probably be done better... I would like to extract the bold parts of the following string: SOMETEXT: ANYTHING_HERE (Old=ANYTHING_HERE, New=ANYTHING_HERE) Some examples could be: ABC: Some_Field (Old=,New=123) ABC: Some_Field (Old=ABCde,New=1234) ABC: Some_Field (Old=Hello World,New=Bye Bye World) So the above would return the following matches: $matches[0] = 'Some_Field'; $matches[1] = ''; $matches[2] = '123'; So far I have the following code: preg_match_all('/^([a-z]*\:(\s?)+)(.+)(\s?)+\(old=(.+)\,(\s?)+new=(.+)\)/i',$string,$matches); The issue with the above is that it returns a match for each separate segment of the string. I do not know how to ensure the string is the correct format using a regular expression without catching and storing the match if that makes sense? So, my question, if not already clear, how I can retrieve just the segments that I want from the above string?

    Read the article

  • Searching for simple variable names like 'c' or 'x' in Emacs.

    - by wpeters
    I often wish to search for variables that are simply called 'c' or 'count'. For example int c, count; Unfortunately when I use an incremental search for 'c' or 'count' I get a lot of unnecessary hits like the 'c' in 'choice', or the 'count' in 'wordcount' which do not interest me. I know Emacs can do i-searches with regular expressions but I don't know the correct regular expression needed to match just 'c' and 'count'. These words are often surrounded by any number of white spaces. Anyone know the regex I can use to narrow my search?

    Read the article

  • Select records from XML column (SQL Server 2005) based on node order

    - by jdoe
    I have a column in a SQL Server 2005 table defined as an XML column. Is there a way to select records from this table based on the order of two nodes in that column? For example, we have the following structure in our XML: <item> <latitude/> <longitude/> </item> I want to see if there are any records that have latitude/longitude in the opposite order i.e. <longitude/> then <latitude/>. I've tried some XPath expressions but with no luck.

    Read the article

  • ASP .NET - What's going on behind an Eval() ?

    - by Amokrane
    Hi, I'm trying to understand how Eval() works for a specific purpose. I'm working on a project I don't really know and I need to read some data and put them in drop down list. These data are already read and are displayed inside an ItemTemplate. I noticed there are read using the Eval() method. Something like: <ItemTemplate> <a href="...=<%# Eval("foo") %>></a> </ItemTemplate> I need to know where Eval is getting these data from in order to discover where I should read them for my drop down list! But I didn't really understand how it works! I know that Eval() evaluates data binding expressions at runtime but where do you think I should take a look at? Thank you

    Read the article

  • GUID.TryParse() ?

    - by Jack Marchetti
    Obviously there is no public GUID.TryParse() in .NET CLR 2.0. So, I was looking into regular expressions [aka googling around to find one] and each time I found one there was a heated argument in the comments section about RegEx A doesn't work, use RegEx B. Then someone would write Regex C yadda yadda So anyway, What I decided to do was this, but I feel bad about it. public static bool IsGuid (string possibleGuid) { try { Guid gid = new Guid(possibleGuid); return true; } catch (Exception ex) { return false; } } Obviously I don't really like this since it's been drilled into me since day one to avoid throwing exceptions if you can defensibly code around it. Does anyonek now why there is no public Guid.TryParse() in the .NET Framework? Does anyone have a real Regular Expression that will work for all GUIDs?

    Read the article

  • IIS7: URL Rewrite - can it be used to hide a CDN path?

    - by Wild Thing
    Hi, I am using Rackspace Cloud CDN (Limelight CDN) for my website. The URLs of the CDN are in the format http://cxxxxxx.cdn.cloudfiles.rackspacecloud.com/something.jpg My domain is mydomain.com. Can I use IIS URL rewriting to show http://cxxxxxx.cdn.cloudfiles.rackspacecloud.com/something.jpg as http://images.mydomain.com/something.jpg? Or is this impossible without the CDN setup accepting my CNAME? If so, can you please help create the URL rewrite rule? (Sorry, don't know how to use regular expressions) Thanks, WT

    Read the article

  • Would it be simply better to use the system's functions rather than use the language?

    - by Nullw0rm
    There are many scenarios where I've questioned PHP's performance with some of its functions, and whether I should build a complex class to handle specific things using its seemingly slow tools. For example, Complex regular expressions with sed and processing with awk would seemingly be exponential in performance rather than making PHP's regular expression and seemingly excessive functions parse and in time manage to finish it. If I were to do a lot of network tasks such as MX lookups/DIGging/retrieving simultaneously I would rather pass it via system() and let the OS handle it itself. There are simply too many functions in PHP, that are inefficient and result in slow pages or can be handled easier by the OS. What are your opinions? Do you think I should do the hard work with the OS in its own/custom functions?

    Read the article

  • Is it possible to "learn" a regular expression by user-provided examples?

    - by DR
    Is it possible to "learn" a regular expression by user-provided examples? To clarify: I do not want to learn regular expressions. I want to create a program which "learns" a regular expression from examples which are interactively provided by a user, perhaps by selecting parts from a text or selecting begin or end markers. Is it possible? Are there algorithms, keywords, etc. which I can Google for? EDIT: Thank you for the answers, but I'm not interested in tools which provide this feature. I'm looking for theoretical information, like papers, tutorials, source code, names of algorithms, so I can create something for myself.

    Read the article

< Previous Page | 57 58 59 60 61 62 63 64 65 66 67 68  | Next Page >