Search Results

Search found 9872 results on 395 pages for 'preg replace callback'.

Page 42/395 | < Previous Page | 38 39 40 41 42 43 44 45 46 47 48 49  | Next Page >

  • Slight confusion of `this` in a JavaScript call back function

    - by thecoshman
    $.ajax({url: path_to_file, cache: false, success: function(html_result){ $("#window_" + this.id + "_cont_buffer").html(html_result);}) Now then. This function call is with in a function of a class. this.id is a property of said class. will this pass the function value of this.id into the string the anonymous function, or will it try to evaluate it when the function actually gets called, thus making no sense. If this is not going to work how I want it to, can you recommend how I achieve this.

    Read the article

  • How to use backreferences in PHP

    - by Slinky
    I want to add a character to the end of each file extension found in a body of text using preg_replace(). Here is some sample text: $string='http://www.mysite.com/expert/images/imageone.jpghttp://www.mysite.com/expert/images/imagetwo.jpg'; This search & replace works fine in TextWrangler, appending a semi colon to file extensions: (\.(jpg|gif|html?|php|tiff?|pdf|png)) \1; Translated to PHP, however does not work, having no effect; no errors. preg_replace("/(\.(jpg|gif|html|php|tif|tiff|pdf|htm|png))/","\\1;",$string);

    Read the article

  • Problem with acceding in DOM with jQuery

    - by Tristan
    Hello, I changed the tree of my JSON-P output, and i cannot access to my object DOM anymore : Here's my output : jsonp1271634374310( {"Inter-Medias": {"name":"Inter-Medias","idGSP":"14","average":"80","services":"8.86"} }); And here's my jQuery script : success: function(data, textStatus, XMLHttpRequest){ widget = data.name; widget += data.average ; .... I know one level is missing, but if I try to do : data.Inter-Medias.name or data.name.name it's still not working. Any idea please ? I will have case where i'll have multiple Ojbect, so i want to display all of them, how to do that ? for (i=0;i < data.length;i++) Does it look right ? Bonus question : i understand function(data, textStatus, XMLHttpRequest) that in case of success this function is triggered, the data is what the script recieved from his request, but i have no idea what textStatus or XMLHttpRequest are here too and why ?! Thank you.

    Read the article

  • Replacing delimiter characters in file path

    - by salvationishere
    I'm developing a C# web application in VS 2008. I let the user select an input file and then I store the file path in a string variable. However, it stores this path as "C:\\folder\\...". So my question is how do I convert this file path into single "\"? To clarify more, this is my code in context. Currently it is entering the If Directory does not Exist section. protected void btnAppend_Click(object sender, EventArgs e) { string fullpath = Page.Request.PhysicalPath; fullpath.Replace('\\', '\'); if (!Directory.Exists(fullpath)) { string msg = "<h1>The upload path doesn't exist: {0}</h1>";

    Read the article

  • replace <br> to new line between pre tag

    - by saturngod
    I want to convert <p>Code is following</p> <pre> &lt;html&gt;<br>&lt;/html&gt; </pre> to <p>Code is following</p> <pre> &lt;html&gt; &lt;/html&gt; </pre> I don't know how to write regular expression for replace between pre tag in PHP. I tried this code http://stackoverflow.com/questions/1517102/replace-newlines-with-br-tags-but-only-inside-pre-tags but it's not working for me.

    Read the article

  • Find and replace numbers in string with regex

    - by James
    What I'm trying to achieve is to replace the numbers in the string with a new values calculated from the (match * int). So the string input looks like: 500g Flour 14g Salt 7g Dry yeast 45ml Olive oil 309ml Water And the result should look like this: 1000g Flour 14g Salt 14g Dry yeast 90ml Olive oil 618 ml Water row["ingredients"] is a DataRow. This is where I'm at: System.Text.RegularExpressions. Regex.Replace(row["ingredients"].ToString(), @"[^/d]", Delegate(Match match) { return match * 2; }, RegexOptions.Multiline); Any solution is greatly appreciated.

    Read the article

  • C5 Generics Collection IntervalHeap<T> -- getting an IPriorityQueueHandle from a T for Replace or De

    - by Jared Updike
    I'm using the Generics Collection library C5 (server down :-( ) and I have an IntervalHeap(T) and I need to Delete or Replace a T that is not the Max or Min. How do I get an IPriorityQueueHandle from my T? The C5 library source code shows that IPriorityQueueHandle(T) has no methods or properties to implement and the compiler thinks my implementation of IPriorityQueueHandle(T) for my T is acceptable. I try to use a T like this: q.Replace(t, t); and the C5 library throws an InvalidCastException because it cannot convert my T to a (Handle).

    Read the article

  • preg_replace only replaces first occurrence then skips to next line

    - by Dom
    Got a problem where preg_replace only replaces the first match it finds then jumps to the next line and skips the remaining parts on the same line that I also want to be replaced. What I do is that I read a CSS file that sometimes have multiple "url(media/pic.gif)" on a row and replace "media/pic.gif" (the file is then saved as a copy with the replaced parts). The content of the CSS file is put into the variable $resource_content: $resource_content = preg_replace('#(url\((\'|")?)(.*)((\'|")?\))#i', '${1}'.url::base(FALSE).'${3}'.'${4}', $resource_content); Does anyone know a solution for why it only replaces the first match per line?

    Read the article

  • jQuery - Change background of input field if text getting replaced

    - by ywickham
    I'm currently using jQuery to restrict a text box to number only input as follows: $('input.numbersOnly').keyup(function () { this.value = this.value.replace(/[^0-9\.]/g,''); }); I'd like to let the user know that what they are typing is being rejected by changing the background color of the field. I know that I can change the background of a field using something like this: $('input.numbersOnly').addClass('alertClass'); My question is, how do I combine the two code examples above so that the color of the field changes as the character is getting replaced? My goal is to alert the user that something is wrong with their input as they type it in the field. Thanks!

    Read the article

  • How can I do the multiple replace in python?

    - by prosseek
    As asked and answered in HERE, I need to replace '[' with '[[]', and ']' with '[]]'. I tried to use s.replace(), but as it's not in place change, I ran as follows to get a wrong anwser. path1 = "/Users/smcho/Desktop/bracket/[10,20]" path2 = path1.replace('[','[[]') path3 = path2.replace(']','[]]') pathName = os.path.join(path3, "*.txt") print pathName -- /Users/smcho/Desktop/bracket/[[[]]10,20[]]/*.txt How can I do the multiple replace in python? Or how can I replace '[' and ']' at the same time?

    Read the article

  • How to replace a multipart message schema in a map without replacing the map

    - by BizTalkMama
    I have an orchestration map that maps two source messages into one destination message. When the schema for one of the source messages changes, I was hoping to be able to click on the input message part and select "Replace Schema" to refresh the schema for just the message part affected. Instead I can only replace the entire multipart message schema with the single message part schema. My only other option seems to be to generate a new map from the orchestration transform shape, but this means I have to recreate all the links in my map... Does anyone know of a more efficient way to update this type of schema?

    Read the article

  • How to add/remove/replace LIST in cookies using C#

    - by MKS
    Hi Guys, How can add/remove/replace LIST in cookies using C#. //Declaring the List for image list List<string> imageList = new List<string>(); foreach (FeaturedPromo promo in base.FeaturedPromos) { imageList.Add(promo.ImageHref); } In above code, I have got a list with all the Image HREF values in it, Now I want to add these values in cookies using C#, after that I can remove that item from cookies and also replace the value with other value of same item in cookies. Please suggest!

    Read the article

  • Can twitter do callbacks?

    - by RenegadeAndy
    Hi! I am wondering if the twitter API supports the following: Whenever I make a post to my twitter account - it also calls a specific URL which I define so I can do something else? Thanks very much, Andy

    Read the article

  • using javascript replace() to match the last occurance of a string

    - by Dave
    I'm building an 'add new row' function for product variations, and I'm struggling with the regex required to match the form attribute keys. So, I'm basically cloning rows, then incrementing the keys, like this (coffeescript): newrow = oldrow.find('select, input, textarea').each -> this.name = this.name.replace(/\[(\d+)\]/, (str, p1) -> "[" + (parseInt(p1, 10) + 1) + "]" ) this.id = this.id.replace(/\_(\d+)\_/, (str, p1) -> "_" + (parseInt(p1, 10) + 1) + "_" ) .end() This correctly increments a field with a name of product[variations][1][name], turning it into product[variations][2][name] BUT Each variation can have multiple options (eg, color can be red, blue, green), so I need to be able turn this product[variations][1][options][2][name] into product[variations][1][options][3][name], leaving the variation key alone. What regex do I need to match only the last occurrence of a key (the options key)?

    Read the article

  • Why do you need "extern C" for in C++ callbacks to C functions?

    - by Artyom
    Hello, I find such examples in Boost code. namespace boost { namespace { extern "C" void *thread_proxy(void *f) { .... } } // anonymous void thread::thread_start(...) { ... pthread_create(something,0,&thread_proxy,something_else); ... } } // boost Why do you actually need this extern "C"? It is clear that thread_proxy function is private internal and I do not expect that it would be mangled as "thread_proxy" because I actually do not need it mangled at all. In fact in all my code that I had written and that runs on may platforms I never used extern "C" and this had worked as-as with normal functions. Why extern "C" is added? My problem is that extern "C" function pollute global name-space and they do not actually hidden as author expects. This is not duplicate! I'm not talking about mangling and external linkage. It is obvious in this code that external linkage is unwanted!

    Read the article

  • Rails: updating an association

    - by Sam
    I have a Reservation model which belongs_to a Sharedorder and so a Sharedorder has_many reservations. Give you a little background. I sharedorder has many reservations and each reservation can have an amount. A sharedorder has three status: 1) reserved, 2) confirmed, 3) and purchased. Here is my problem. When a reservation gets added to a sharedorder or an existing reservation's amount is updated I need this to affect the associated sharedoder because the status listed latter should only change when 100% of the reservations have been placed and so on. Here are the things I have tried: . class Reservation < ActiveRecord::Base before_save :sharedorder_reserved_status def sharedorder_reserved_status if self.sharedorder.reserved_percent(reservations_to_be_added) >= 100 && !self.sharedorder.reserved self.sharedorder.update_attribute(:reserved, true) self.sharedorder.update_attribute(:reserved_at, Time.now) end end def reservations_to_be_added if self.new_record? self.amount elsif self.amount_changed? self.amount - self.amount_was else 0 end end end And then in the Sharedorder model: class Sharedorder < ActiveRecord::Base def reserved_percent(amount_change) (((reserved_sum + amount_change).to_f / self.product.twenty_hq_size.to_f)*100).to_i end def reserved_sum if !@reserved_sum reserved_sum = 0 reserved_reservations.collect {|x| reserved_sum += x.amount } reserved_sum else @reserved_sum end end def reserved_reservations @reserved_reservations ||= Reservation.find(:all, :conditions => ['canceled = ? AND sharedorder_id = ?', false, self.id ]) end end I have also tried :touch => true on the reservation model to update the sharedorder put for some reason it doesn't seem to include the latest reservation being added or being updated. So what I'm trying to do is update the status of the sharedorder if a certain percent is reached and I have to send the additional amounts the the sharedorder for it to know to include additional reservations or updates on existing ones. How should I do this?

    Read the article

  • Problem with accessing in DOM with jQuery

    - by Tristan
    Hello, I changed the tree of my JSON-P output, and i cannot access to my object DOM anymore : Here's my output : jsonp1271634374310( {"Inter-Medias": {"name":"Inter-Medias","idGSP":"14","average":"80","services":"8.86"} }); And here's my jQuery script : success: function(data, textStatus, XMLHttpRequest){ widget = data.name; widget += data.average ; .... I know one level is missing, but if I try to do : data.Inter-Medias.name or data.name.name it's still not working. Any idea please ? I will have case where i'll have multiple Ojbect, so i want to display all of them, how to do that ? for (i=0;i < data.length;i++) Does it look right ? Bonus question : i understand function(data, textStatus, XMLHttpRequest) that in case of success this function is triggered, the data is what the script recieved from his request, but i have no idea what textStatus or XMLHttpRequest are here too and why ?! Thank you.

    Read the article

  • Replace # keyword from to the strings from the specified <div></div> using Jquery

    - by user568085
    Hi friends, I have problem to replace keyword from input string I have <div id="Wrap"> <span class="common"><div id="main0"> to test it #sky </div></span> </div> I want to like this : <div id="Wrap"> <span class="common"> <div id="main0"> to test <a href="http://mysite.com/search?q=#sky">#sky</a> </div> </span> </div> I tried with replace in jquery but not getting ... I finding solution in jquery or javascript Please help me... abhishek

    Read the article

  • optimize a string.Format + replace.

    - by acidzombie24
    I have this function. The visual studio profile marked the line with string.Format as hot and were i spend much of my time. How can i write this loop more efficiently? public string EscapeNoPredicate(string sz) { var s = new StringBuilder(sz); s.Replace(sepStr, sepStr + sepStr); foreach (char v in IllegalChars) { string s2 = string.Format("{0}{1:X2}", seperator, (Int16)v); s.Replace(v.ToString(), s2); } return s.ToString(); }

    Read the article

  • Why do you need "extern C" for C++ callbacks to C functions?

    - by Artyom
    Hello, I find such examples in Boost code. namespace boost { namespace { extern "C" void *thread_proxy(void *f) { .... } } // anonymous void thread::thread_start(...) { ... pthread_create(something,0,&thread_proxy,something_else); ... } } // boost Why do you actually need this extern "C"? It is clear that thread_proxy function is private internal and I do not expect that it would be mangled as "thread_proxy" because I actually do not need it mangled at all. In fact in all my code that I had written and that runs on may platforms I never used extern "C" and this had worked as-as with normal functions. Why extern "C" is added? My problem is that extern "C" function pollute global name-space and they do not actually hidden as author expects. This is not duplicate! I'm not talking about mangling and external linkage. It is obvious in this code that external linkage is unwanted! Answer: Calling convention of C and C++ functions are not necessary the same, so you need to create one with C calling convention. See 7.5 (p4) of C++ standard.

    Read the article

  • Best solution to wait for all ajax callbacks to be executed

    - by glaz666
    Hi! Imagine we have to sources to be requested by ajax. I want to perform some actions when all callbacks are triggered. How this can be done besides this approach: (function($){ var sources = ['http://source1.com', 'http://source2.com'], guard = 0, someHandler = function() { if (guard != sources.length) { return; } //do some actions }; for (var idx in sources) { $.getJSON(sources[idx], function(){ guard++; someHandler(); }) } })(jQuery) What I don't like here is that in this case I can't handle response failing (eg. I can't set timeout for response to come) and overall approach (I suppose there should be a way to use more power of functional programming here) Any ideas? Regards!

    Read the article

  • [c++] accessing the hidden 'this' pointer

    - by Kyle
    I have a GUI architecture wherein elements fire events like so: guiManager->fireEvent(BUTTON_CLICKED, this); Every single event fired passes 'this' as the caller of the event. There is never a time I dont want to pass 'this', and further, no pointer except for 'this' should ever be passed. This brings me to a problem: How can I assert that fireEvent is never given a pointer other than 'this', and how can I simplify (and homogenize) calls to fireEvent to just: guiManager->fireEvent(BUTTON_CLICKED); At this point, I'm reminded of a fairly common compiler error when you write something like this: class A { public: void foo() {} }; class B { void oops() { const A* a = new A; a->foo(); } }; int main() { return 0; } Compiling this will give you ../src/sandbox.cpp: In member function ‘void B::oops()’: ../src/sandbox.cpp:7: error: passing ‘const A’ as ‘this’ argument of ‘void A::foo()’ discards qualifiers because member functions pass 'this' as a hidden parameter. "Aha!" I say. This (no pun intended) is exactly what I want. If I could somehow access the hidden 'this' pointer, it would solve both issues I mentioned earlier. The problem is, as far as I know you can't (can you?) and if you could, there would be outcries of "but it would break encapsulation!" Except I'm already passing 'this' every time, so what more could it break. So, is there a way to access the hidden 'this', and if not are there any idioms or alternative approaches that are more elegant than passing 'this' every time?

    Read the article

  • Javascript Replace Child/Loop issue

    - by Charles John Thompson III
    I have this really bizarre issue where I have a forloop that is supposed to replace all divs with the class of "original" to text inputs with a class of "new". When I run the loop, it only replaces every-other div with an input, but if I run the loop to just replace the class of the div and not change the tag to input, it does every single div, and doesn't only do every-other. Here is my loop code, and a link to the live version: live version here function divChange() { var divs = document.getElementsByTagName("div"); for (var i=0; i<divs.length; i++) { if (divs[i].className == 'original') { var textInput = document.createElement('input'); textInput.className = 'new'; textInput.type = 'text'; textInput.value = divs[i].innerHTML; var parent = divs[i].parentNode; parent.replaceChild(textInput, divs[i]); } } }

    Read the article

  • How to deal with callback to your UIController after your UIController unloads?

    - by erotsppa
    Suppose your controller is a table view and one of the cells you are going off to do a length task (say download a thumbnail) to be viewed in the cell. Typically you would have the network call do a callback to your controller when it is done downloading. The callback can then reload the table or do some other form of UI update (hides a spinner etc). However, what if the controller is unloaded? Say the user navigated away from this controller and it got released? What happens? Will the callback still work despite the controller now not in memory? Also, if the callback operates on some objects (say the UITableView) what happens when the controller is deallocated? I suppose the controller can release all the objects and the callback would just be calling methods on nil to prevent crash. But is this the convention?

    Read the article

< Previous Page | 38 39 40 41 42 43 44 45 46 47 48 49  | Next Page >