Search Results

Search found 9273 results on 371 pages for 'complex strings'.

Page 2/371 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Multiplying complex with constant in C++

    - by Atilla Filiz
    The following code fails to compile #include <iostream> #include <cmath> #include <complex> using namespace std; int main(void) { const double b=3; complex <double> i(0, 1), comp; comp = b*i; comp=3*i; return 0; } with error: no match for ‘operator*’ in ‘3 * i’ What is wrong here, why cannot I multiply with immediate constants?

    Read the article

  • Convert cell array of cells into cell array of strings in MATLAB

    - by yuk
    Using regexp with tokens on cell array of strings I've got cell array of cells. Here is simplified example: S = {'string 1';'string 2';'string 3'}; res = regexp(S,'(\d)','tokens') res = {1x1 cell} {1x1 cell} {1x1 cell} res{2}{1} ans = '2' I know I have only one match per cell string in S. How I can convert this output into cell arrays of strings in a vectorized form?

    Read the article

  • How to remove list of words from strings

    - by zeljko
    What I would like to do (in Clojure): For example, I have a vector of words that need to be removed: (def forbidden-words [":)" "the" "." "," " " ...many more...]) ... and a vector of strings: (def strings ["the movie list" "this.is.a.string" "haha :)" ...many more...]) So, each forbidden word should be removed from each string, and the result, in this case, would be: ["movie list" "thisisastring" "haha"]. How to do this ?

    Read the article

  • Print Alternating Characters From Two Strings (Interleaving) Using Recursion Java

    - by babi2balla
    I'm trying to write a method that uses recursion to print the string formed by "interleaving" the strings str1 and str2. In other words, it should alternate characters from the two strings: the first character from str1, followed by the first character from str2, followed by the second character from str1, followed by the second character from str2, etc. How would I go about this? Any ideas are greatly appreciated!! Thanks

    Read the article

  • Encode complex number as RGB pixel

    - by Vi
    How is it better to encode a complex number into RGB pixel and vice versa? Probably (logarithm of) an absolute value goes to brightness and an argument goes to hue. Desaturated pixes should receive randomized argument in reverse transformation. Something like: 0 - (0,0,0) 1 - (255,0,0) -1 - (0,255,255) 0.5 - (128,0,0) i - (255,255,0) -i - (255,0,255) (0,0,0) - 0 (255,255,255) - e^(i * random) (128,128,128) - 0.5 * e^(i *random) (0,128,128) - -0.5 Are there ready-made formulas for that?

    Read the article

  • Complex String Processing - well complex to me

    - by percent20
    I am calling a web service and all I get back is a giant blob of text. I am left to process it myself. Problem is not all lines are necessarily the same. They each have 2 or 3 sections to them and they are similar. Here are the most common examples text1 [text2] /text3/ text1/test3 text1[text2]/text3 text1 [text2] /text /3 here/ I am not exactly sure how to approach this problem. I am not too good at doing anything advanced as far as manipulating strings. I was thinking using a regular expression might work, but not too sure on that either. If I can get each of these 3 sections broken up it is easier from there to do the rest. its just there doesn't seem to be any uniformity to the main 3 sections that I know how to work with.

    Read the article

  • Best way to manipulate and compare strings

    - by vtortola
    I'm developing a REST service, so a request could be something like this: /Data/Main/Table=Customers/ I need to get the segments one by one, and for each segment I will decide wich object I'm going to use, after I'll pass to that object the rest of the query so it can decide what to do next. Basically, the REST query is a path on a tree :P This imply lots String operations (depending on the query complexity), but StringBuilder is useful just for concatenations and remove, you cannot perform a search with IndexOf or similar. I've developed this class that fulfill my requirement, but the problem is that is manipulating Strings, so every time I get one segment ... I'll create extra Strings because String is an inmutable data type: public class RESTQueryParser { String _query; public RESTQueryParser(String query) { _query = query; } public String GetNext() { String result = String.Empty; Int32 startPosition = _query.StartsWith("/", StringComparison.InvariantCultureIgnoreCase) ? 1 : 0; Int32 i = _query.IndexOf("/", startPosition, StringComparison.InvariantCultureIgnoreCase) - 1; if (!String.IsNullOrEmpty(_query)) { if (i < 0) { result = _query.Substring(startPosition, _query.Length - 1); _query = String.Empty; } else { result = _query.Substring(startPosition, i); _query = _query.Remove(0, i + 1); } } return result; } } The server should support a lot of calls, and the queries could be huge, so this is gonna be a very repetitive task. I don't really know how big is the impact on the memory and the performance, I've just readed about it in some books. Should I implement a class that manage a Char[] instead Strings and implement the methods that I want? Or should be ok with this one? Regular expressions maybe?

    Read the article

  • Java Bucket Sort on Strings

    - by Michael
    I can't figure out what would be the best way to use Bucket Sort to sort a list of strings that will always be the same length. An algorithm would look like this: For the last character position down to the first: For each word in the list: Place the word into the appropriate bucket by current character For each of the 26 buckets(arraylists) Copy every word back to the list I'm writing in java and I'm using an arraylist for the main list that stores the unsorted strings. The strings will be five characters long each. This is what I started. It just abrubdly stops within the second for loop because I don't know what to do next or if I did the first part right. ArrayList<String> count = new ArrayList<String>(26); for (int i = wordlen; i > 0; i--) { for (int j = 0; i < myList.size(); i++) myList.get(j).charAt(i) } Thanks in advanced.

    Read the article

  • Why strings behave like ValueType

    - by AJP
    I was perplexed after executing this piece of code, where strings seems to behave as if they are value types. I am wondering whether the assignment operator is operating on values like equality operator for strings. Here is the piece of code I did to test this behavior. using System; namespace RefTypeDelimma { class Program { static void Main(string[] args) { string a1, a2; a1 = "ABC"; a2 = a1; //This should assign a1 reference to a2 a2 = "XYZ"; //I expect this should change the a1 value to "XYZ" Console.WriteLine("a1:" + a1 + ", a2:" + a2);//Outputs a1:ABC, a2:XYZ //Expected: a1:XYZ, a2:XYZ (as string being a ref type) Proc(a2); //Altering values of ref types inside a procedure //should reflect in the variable thats being passed into Console.WriteLine("a1: " + a1 + ", a2: " + a2); //Outputs a1:ABC, a2:XYZ //Expected: a1:NEW_VAL, a2:NEW_VAL (as string being a ref type) } static void Proc(string Val) { Val = "NEW_VAL"; } } } In the above code if I use a custom classes instead of strings, I am getting the expected behavior. I doubt is this something to do with the string immutability? welcoming expert views on this.

    Read the article

  • difference fixed width strings and zero-terminated strings

    - by robUK
    Hello, gcc 4.4.4 c89 I got into a recent discussion about "fixed width strings" and "zero terminated strings". When I think about this. They seem to be the same thing. A string with a terminating null. i.e. char *name = "Joe bloggs"; Is a fixed width string that cannot be changed. And also has a terminating null. Also in the discussion I was told that strncpy should never been used on 'zero terminated strings'. Many thanks for any susgestions,

    Read the article

  • Excel CSV import treating quoted strings of numbers as numeric values, not strings

    - by MichaelOryl
    I've got a web application that is exporting its data to a CSV file. Here's one example row of the CSV file in question: 28,"65154",02/21/2013 00:00,"false","0316295","8316012,8315844","MALE" Since I can't post an image, I'll have to explain the results in Excel. The "0316295" field gets turned into a number and the leading 0 goes away. The "8316012,8315844" gets interpreted as one single number: 83,160,128,315,844. That is, most obviously, not the intended result. I've seen people recommend a leading single quote for such cases, but that doesn't really work either. 28,"65154",02/21/2013 00:00,"false","'0316295","'8316012,8315844","MALE" The single quote is visible at all times in the cell in Excel, though if I enter a number with a leading single quote myself, it shows just the intended string and not the single quote with the string. Importing is not the same as typing, it seems. Anybody have a solution here?

    Read the article

  • Immutable Dot Net strings

    - by klork
    I usually define my string variables in vb.net as Dim f_sName as string=String.Empty f_sName = "foo" Given the immutable nature of strings in .net, is there a better way to initialize strings and deal with the "Variable 'f_sName ' is used before it has been assigned a value. A null reference exception could result at runtime." warning? Also for classes that do not have constructors which accept no arguments such as System.Net.Sockets.NetworkStream, what is the best way to define and initialize a variable of that type? All comments are highly appreciated. Thanks

    Read the article

  • complex sql which runs extremely slow when the query has order by clause

    - by basit.
    I have following complex query which I need to use. When I run it, it takes 30 to 40 seconds. But if I remove the order by clause, it takes 0.0317 sec to return the result, which is really fast compare to 30 sec or 40. select DISTINCT media.* , username from album as album , album_permission as permission , user as user, media as media where ((media.album_id = album.album_id and album.private = 'yes' and album.album_id = permission.album_id and (permission.email = '' or permission.user_id = '') ) or (media.album_id = album.album_id and album.private = 'no' ) or media.album_id = '0' ) and media.user_id = user.user_id and media.media_type = 'video' order by media.id DESC LIMIT 0,20 The id on order by is primary key which is indexed too. So I don't know what is the problem. I also have album and album permission table, just to check if media is public or private, if private then check if user has permission or not. I was thinking maybe that is causing the issue. What if I did this in sub query, would that work better? Also can someone help me write that sub query, if that is the solution? If you can't help write it, just at least tell me. I'm really going crazy with this issue.. SOLUTION MAYBE Yes, I think sub-query would be best solution for this, because the following query runs at 0.0022 seconds. But I'm not sure if validation of an album would be accurate or not, please check. select media.*, username from media as media , user as user where media.user_id = user.user_id and media.media_type = 'video' and media.id in (select media2.id from media as media2 , album as album , album_permission as permission where ((media2.album_id = album.album_id and album.private = 'yes' and album.album_id = permission.album_id and (permission.email = '' or permission.user_id = '')) or (media.album_id = album.album_id and album.private = 'no' ) or media.album_id = '0' ) and media.album_id = media2.album_id ) order by media.id DESC LIMIT 0,20

    Read the article

  • [C++] Index strings by other strings

    - by mcco
    Hello, I need to index specific strings with other strings and I can't really find a good way to do so. I tried to use tr1::unordered_map, but I'm having some difficulties using it. If someone could tell me what is the best way to do that I'd be really grateful :) I also need to index objects by a number (numbers are not in order so I can't use a vector)

    Read the article

  • ASP.MVC 1.0 complex ViewModel not populating on Action

    - by Graham
    Hi, I'm 3 days into learning MVC for a new project and i've managed to stumble my way over the multitude of issues I've come across - mainly about something as simple as moving data to a view and back into the controller in a type-safe (and manageable) manner. This is the latest. I've seen this reported before but nothing advised has seemed to work. I have a complex view model: public class IndexViewModel : ApplicationViewModel { public SearchFragment Search { get; private set; } public IndexViewModel() { this.Search = new SearchFragment(); } } public class SearchFragment { public string ItemId { get; set; } public string Identifier { get; set; } } This maps to (the main Index page): %@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IndexViewModel>" %> <asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server"> <% Html.BeginForm("Search", AvailableControllers.Search, FormMethod.Post); %> <div id="search"> <% Html.RenderPartial("SearchControl", Model.Search); %> </div> <% Html.EndForm(); %> </asp:Content> and a UserControl: <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<SearchFragment>" %> <p> <label for="itemId"> <%= Html.Resource("ItemId") %></label> <%= Html.TextBox("itemId", Model.ItemId)%> </p> <p> <label for="title"> <%= Html.Resource("Title") %></label> <%= Html.TextBox("identifier", Model.Identifier)%> </p> <p> <input type="submit" value="<%= Html.Resource("Search") %>" name="search" /> </p> This is returned to the following method: [AcceptVerbs(HttpVerbs.Post)] public ActionResult Search(IndexViewModel viewModel) { .... } My problem is that when the view model is rehydrated from the View into the ViewModel, the SearchFragment elements are null. I suspect this is because the default model binder doesn't realise the HTML ItemId and Identifier elements rendered inline in the View map to the SearchFragment class. When I have two extra properties (ItemId and Identifier) in the IndexViewModel, the values are bound correctly. Unfortunately, as far as I can tell, I must use the SearchFragment as I need this to strongly type the Search UserControl... as the control can be used anywhere it can operate under any parent view. I really don't want to make it use "magic strings". There's too much of that going on already IMO. I've tried prefixing the HTML with "Search." in the hope that the model binder would recognise "Search.ItemId" and match to the IndexViewModel "Search" property and the ItemId within it, but this doesn't work. I fear I'm going to have to write my own ModelBinder to do this, but surely this must be something you can do out-of-the-box?? Failing that is there any other suggestions (or link to someone who has already done this?) Here's hoping....

    Read the article

  • Why is Perl's Math::Complex taking up so much time when I try acos(1)?

    - by synapz
    While trying to profile my Perl program, I find that Math::Complex is taking up a lot of time with what looks like some kind of warning. Also, my code shouldn't have any complex numbers being generated or used, so I am not sure what it is doing in Math::Complex, anyway. Here's the FastProf output for the most expensive lines: /usr/lib/perl5/5.8.8/Math/Complex.pm:182 1.55480 276232: _cannot_make("real part", $re) unless $re =~ /^$gre$/; /usr/lib/perl5/5.8.8/Math/Complex.pm:310 1.01132 453641: sub cartesian {$_[0]->{c_dirty} ? /usr/lib/perl5/5.8.8/Math/Complex.pm:315 0.97497 562188: sub set_cartesian { $_[0]->{p_dirty}++; $_[0]->{c_dirty} = 0; /usr/lib/perl5/5.8.8/Math/Complex.pm:189 0.86302 276232: return $self; /usr/lib/perl5/5.8.8/Math/Complex.pm:1332 0.85628 293660: $self->{display_format} = { %display_format }; /usr/lib/perl5/5.8.8/Math/Complex.pm:185 0.81529 276232: _cannot_make("imaginary part", $im) unless $im =~ /^$gre$/; /usr/lib/perl5/5.8.8/Math/Complex.pm:1316 0.78749 293660: my %display_format = %DISPLAY_FORMAT; /usr/lib/perl5/5.8.8/Math/Complex.pm:1335 0.69534 293660: %{$self->{display_format}} : /usr/lib/perl5/5.8.8/Math/Complex.pm:186 0.66697 276232: $self->set_cartesian([$re, $im ]); /usr/lib/perl5/5.8.8/Math/Complex.pm:170 0.62790 276232: my $self = bless {}, shift; /usr/lib/perl5/5.8.8/Math/Complex.pm:172 0.56733 276232: if (@_ == 0) { /usr/lib/perl5/5.8.8/Math/Complex.pm:316 0.53179 281094: $_[0]->{'cartesian'} = $_[1] } /usr/lib/perl5/5.8.8/Math/Complex.pm:1324 0.48768 293660: if (@_ == 1) { /usr/lib/perl5/5.8.8/Math/Complex.pm:1319 0.44835 293660: if (exists $self->{display_format}) { /usr/lib/perl5/5.8.8/Math/Complex.pm:1318 0.40355 293660: if (ref $self) { # Called as an object method /usr/lib/perl5/5.8.8/Math/Complex.pm:187 0.39950 276232: $self->display_format('cartesian'); /usr/lib/perl5/5.8.8/Math/Complex.pm:1315 0.39312 293660: my $self = shift; /usr/lib/perl5/5.8.8/Math/Complex.pm:1331 0.38087 293660: if (ref $self) { # Called as an object method /usr/lib/perl5/5.8.8/Math/Complex.pm:184 0.35171 276232: $im ||= 0; /usr/lib/perl5/5.8.8/Math/Complex.pm:181 0.34145 276232: if (defined $re) { /usr/lib/perl5/5.8.8/Math/Complex.pm:171 0.33492 276232: my ($re, $im); /usr/lib/perl5/5.8.8/Math/Complex.pm:390 0.20658 128280: my ($z1, $z2, $regular) = @_; /usr/lib/perl5/5.8.8/Math/Complex.pm:391 0.20631 128280: if ($z1->{p_dirty} == 0 and ref $z2 and $z2->{p_dirty} == 0) { Thanks for any help!

    Read the article

  • Using fgets to read strings from file in C

    - by Ivan
    I am trying to read strings from a file that has each string on a new line but I think it reads a newline character once instead of a string and I don't know why. If I'm going about reading strings the wrong way please correct me. i=0; F1 = fopen("alg.txt", "r"); F2 = fopen("tul.txt", "w"); if(!feof(F1)) { do{ //start scanning file fgets(inimene[i].Enimi, 20, F1); fgets(inimene[i].Pnimi, 20, F1); fgets(inimene[i].Kood, 12, F1); printf("i=%d\nEnimi=%s\nPnimi=%s\nKaad=%s",i,inimene[i].Enimi,inimene[i].Pnimi,inimene[i].Kood); i++;} while(!feof(F1));}; /*finish getting structs*/ The printf is there to let me see what was read into what and here is the result i=0 Enimi=peter Pnimi=pupkin Kood=223456iatb i=1 Enimi= Pnimi=masha Kaad=gubkina i=2 Enimi=234567iasb Pnimi=sasha Kood=dudkina As you can see after the first struct is read there is a blank(a newline?) onct and then everything is shifted. I suppose I could read a dummy string to absorb that extra blank and then nothing would be shifted, but that doesn't help me understand the problem and avoid in the future.

    Read the article

  • C++: Efficiently adding integers to strings

    - by Shinka
    I know how to add integers to strings, but I'm not sure I'm doing it in an efficient matters. I have a class where I often have to return a string plus an integer (a different integer each time), in Java I would do something like public class MyClass { final static String S = "MYSTRING"; private int id = 0; public String getString() { return S + (id++); } } But in C++ I have to do; class MyClass { private: std::string S; // For some reason I can't do const std::string S = "MYSTRING"; int id; public: MyClass() { S = "MYSTRING"; id = 0; } std::string getString() { std::ostringstream oss; oss << S << id++; return oss.str(); } } An additional constraint: I don't want (in fact, in can't) use Boost or any other librairies, I'll have to work with the standard library. So the thing is; the code works, but in C++ I have to create a bunch of ostringstream objects, so it seems inefficient. To be fair, perhaps Java do the same and I just don't notice it, I say it's inefficient mostly because I know very little about strings. Is there a more efficient way to do this ?

    Read the article

  • Why does C++ mandate that complex only be instantiated for float, double, or long double?

    - by templatetypedef
    According to the C++ ISO spec, §26.2/2: The effect of instantiating the template complex for any type other than float, double or long double is unspecified. Why would the standard authors explicitly add this restriction? This makes it unspecified, for example, what happens if you make complex<int> or a complex<MyCustomFixedPointType> and seems like an artificial restriction. Is there a reason for this limitation? Is there a workaround if you want to instantiate complex with your own custom type? I'm primarily asking this question because of this earlier question, in which the OP was confused as to why abs was giving bizarre outputs for complex<int>. That said, this still doesn't quite make sense given that we also might want to make complex numbers out of fixed-points types, higher-precision real numbers, etc. Thanks!

    Read the article

  • Python to MATLAB: exporting list of strings using scipy.io

    - by user292461
    I am trying to export a list of text strings from Python to MATLAB using scipy.io. I would like to use scipy.io because my desired .mat file should include both numerical matrices (which I learned to do here) and text cell arrays. I tried: import scipy.io my_list = ['abc', 'def', 'ghi'] scipy.io.savemat('test.mat', mdict={'my_list': my_list) In MATLAB, I load test.mat and get a character array: my_list = adg beh cfi How do I make scipy.io export a list into a MATLAB cell array?

    Read the article

  • Java strings and substrings

    - by omaxgreen
    hey folks, Can someone help me with this Java problem? I want to write a method that takes two strings as arguments and returns true if each character (including space and punctuation) that appears in one string also appears in the other. Thanks

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >