Search Results

Search found 36490 results on 1460 pages for 'string replacement'.

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

  • String Occurance Counting Algorithm

    - by Hellnar
    Hello, I am curious what is the most efficient algorithm (or commonly used) to count the number of occurances of a string in a chunck of text. From what I read, Boyer–Moore string search algorithm is the standard for string search but I am not sure if counting occurance in an efficient way would be same as searching a string. In python this is what I want: text_chunck = "one two three four one five six one" occurance_count(text_chunck, "one") # gives 3. Regards EDIT: It seems like python str.count serves me such method however I am not able to find what algorithm it uses.

    Read the article

  • C++ String tokenisation from 3D .obj files

    - by Ben
    I'm pretty new to C++ and was looking for a good way to pull the data out of this line. A sample line that I might need to tokenise is f 11/65/11 16/70/16 17/69/17 I have a tokenisation method that splits strings into a vector as delimited by a string which may be useful static void Tokenise(const string& str, vector<string>& tokens, const string& delimiters = " ") The only way I can think of doing it is to tokenise with " " as a delimiter, remove the first item from the resulting vector, then tokenise each part by itself. Is there a good way to do this all in one?

    Read the article

  • string in c++,question

    - by user189364
    Hi, I created a program in C++ that remove commas (') from a given integer. i.e. 2,00,00 would return 20000. I am not using any new space. Here is the program i created void removeCommas(string& str1,int len) { int j=0; for(int i=0;i<len;i++) { if(str1[i] == ',') continue; else { str1[j] =str1[i]; j++; } } str1[j] = '\0'; } void main() { string str1; getline(cin,str1); int i = str1.length(); removeCommas(str1,i); cout<<"the new string "<<str1<<endl; } Here is the result i get : Input : 2,000,00 String length =8 Output = 200000 0 Length = 8 My question is that why does it show the length has 8 in output and shows the rest of string when i did put a null character. It should show output as 200000 and length has 6.

    Read the article

  • A simple string array Iteration in C# .NET doesn't work

    - by met.lord
    This is a simple code that should return true or false after comparing each element in a String array with a Session Variable. The thing is that even when the string array named 'plans' gets the right attributes, inside the foreach it keeps iterating only over the first element, so if the Session Variable matches other element different than the first one in the array it never returns true... You could say the problem is right there in the foreach cicle, but I cant see it... I've done this like a hundred times and I can't understand what am I doing wrong... Thank you protected bool ValidatePlans() { bool authorized = false; if (RequiredPlans.Length > 0) { string[] plans = RequiredPlans.Split(','); foreach (string plan in plans) { if (MySessionInfo.Plan == plan) authorized = true; } } return authorized; }

    Read the article

  • How to check if string contains a string in string array

    - by Abu Hamzah
    edit: the order might change as you can see in the below example, both string have same name but different order.... How would you go after checking to see if the both string array match? the below code returns true but in a reality its should return false since I have extra string array in the _check what i am trying to achieve is to check to see if both string array have same number of strings. string _exists = "Adults,Men,Women,Boys"; string _check = "Men,Women,Boys,Adults,fail"; if (_exists.All(s => _check.Contains(s))) //tried Equal { return true; } else { return false; }

    Read the article

  • std::string.resize() and std::string.length()

    - by dreamlax
    I'm relatively new to C++ and I'm still getting to grips with the C++ Standard Library. To help transition from C, I want to format a std::string using printf-style formatters. I realise stringstream is a more type-safe approach, but I find myself finding printf-style much easier to read and deal with (at least, for the time being). This is my function: using namespace std; string formatStdString(const string &format, ...) { va_list va; string output; size_t needed; size_t used; va_start(va, format); needed = vsnprintf(&output[0], 0, format.c_str(), va); output.resize(needed + 1); // for null terminator?? used = vsnprintf(&output[0], output.capacity(), format.c_str(), va); // assert(used == needed); va_end(va); return output; } This works, kinda. A few things that I am not sure about are: Do I need to make room for a null terminator, or is this unnecessary? Is capacity() the right function to call here? I keep thinking length() would return 0 since the first character in the string is a '\0'. Occasionally while writing this string's contents to a socket (using its c_str() and length()), I have null bytes popping up on the receiving end, which is causing a bit of grief, but they seem to appear inconsistently. If I don't use this function at all, no null bytes appear.

    Read the article

  • Lenovo Wi-Fi Replacement

    - by user22910
    I recently got my T500 with a very poor signal Wi-Fi, Thinkpad BGN, a Realtek chipset. I would like to replace my Wi-Fi card with either the Intel WiFi Link 5100 or 5300. However, I read somewhere that Lenovo specfically "whitelist" their Wi-Fi cards to only work with their laptops. I could not find any of the Intel Wi-Fi, moreover any Wi-Fi cards on the Lenovo site. So, I went to hunt around in Amazon and found several sellers. Plus what sort of card do I require? There is a difference between mini cards and the full sized card, though I do not know which one my laptop supports. Here are the specifications for my laptop: http://privatepaste.com/8b0537bce0 I would like to have confirmation which one of these specific cards as posted below will work on my laptop (or the one you recommend to have): Intel Wifi Link 5300 Intel WiFi Link 5100 - Network adapter - PCI Express Mini Card - 802.11b, 802.11a, 802.11g, 802.11n (draft 2.0) Intel WiFi Link 5100 - Network adapter - PCI Express Half Mini Card - 802.11b, 802.11a, 802.11g, 802.11n (draft) Intel WiFi Link 5300 - Network adapter - PCI Express Mini Card - 802.11b, 802.11a, 802.11g, 802.11n (draft)

    Read the article

  • SQL SERVER – Order By Numeric Values Formatted as String

    - by pinaldave
    When I was writing this blog post I had a hard time to come up with the title of the blog post so I did my best to come up with one. Here is the reason why? I wrote a blog post earlier SQL SERVER – Find First Non-Numeric Character from String. One of the questions was that how that blog can be useful in real life scenario. This blog post is the answer to that question. Let us first see a problem. We have a table which has a column containing alphanumeric data. The data always has first as an integer and later part as a string. The business need is to order the data based on the first part of the alphanumeric data which is an integer. Now the problem is that no matter how we use ORDER BY the result is not produced as expected. Let us understand this with example. Prepare a sample data: -- How to find first non numberic character USE tempdb GO CREATE TABLE MyTable (ID INT, Col1 VARCHAR(100)) GO INSERT INTO MyTable (ID, Col1) SELECT 1, '1one' UNION ALL SELECT 2, '11eleven' UNION ALL SELECT 3, '2two' UNION ALL SELECT 4, '22twentytwo' UNION ALL SELECT 5, '111oneeleven' GO -- Select Data SELECT * FROM MyTable GO The above query will give following result set. Now let us use ORDER BY COL1 and observe the result along with Original SELECT. -- Select Data SELECT * FROM MyTable GO -- Select Data SELECT * FROM MyTable ORDER BY Col1 GO The result of the table is not as per expected. We need the result in following format. Here is the good example of how we can use PATINDEX. -- Use of PATINDEX SELECT ID, LEFT(Col1,PATINDEX('%[^0-9]%',Col1)-1) 'Numeric Character', Col1 'Original Character' FROM MyTable ORDER BY LEFT(Col1,PATINDEX('%[^0-9]%',Col1)-1) GO We can use PATINDEX to identify the length of the digit part in the alphanumeric string (Remember: Our string has a first part as an int always. It will not work in any other scenario). Now you can use the LEFT function to extract the INT portion from the alphanumeric string and order the data according to it. You can easily clean up the script by dropping following table. DROP TABLE MyTable GO Here is the complete script so you can easily refer it. -- How to find first non numberic character USE tempdb GO CREATE TABLE MyTable (ID INT, Col1 VARCHAR(100)) GO INSERT INTO MyTable (ID, Col1) SELECT 1, '1one' UNION ALL SELECT 2, '11eleven' UNION ALL SELECT 3, '2two' UNION ALL SELECT 4, '22twentytwo' UNION ALL SELECT 5, '111oneeleven' GO -- Select Data SELECT * FROM MyTable GO -- Select Data SELECT * FROM MyTable ORDER BY Col1 GO -- Use of PATINDEX SELECT ID, Col1 'Original Character' FROM MyTable ORDER BY LEFT(Col1,PATINDEX('%[^0-9]%',Col1)-1) GO DROP TABLE MyTable GO Well, isn’t it an interesting solution. Any suggestion for better solution? Additionally any suggestion for changing the title of this blog post? Reference : Pinal Dave (http://blog.SQLAuthority.com) Filed under: PostADay, SQL, SQL Authority, SQL Query, SQL Server, SQL String, SQL Tips and Tricks, T SQL, Technology

    Read the article

  • Python string formatting when string contains "%s" without escaping

    - by Stephen Gornick
    When formatting a string, my string may contain a modulo "%" that I do not wish to have converted. I can escape the string and change each "%" to "%%" as a workaround. e.g., 'Day old bread, 50%% sale %s' % 'today!' output: 'Day old bread, 50% sale today' But are there any alternatives to escaping? I was hoping that using a dict would make it so Python would ignore any non-keyword conversions. e.g., 'Day old bread, 50% sale %(when)s' % {'when': 'today'} but Python still sees the first modulo % and gives a: TypeError: not enough arguments for format string

    Read the article

  • String Formatting Tricks/Docs

    - by Meltemi
    Was reading the response by Shaggy Frog to this post and was intrigued by the following line of code: NSLog(@"%@", [NSString stringWithFormat:@"%@:%*s%5.2f", key, padding, " ", [object floatValue]]); I know string formatting is an age old art but I'm kinda doing the end around into Cocoa/Obj-C programming and skipped a few grades along the way. Where is a good (best) place to learn all the string formatting tricks allowed in NSString's stringWithFormat? I'm familiar with Apple's String Format Specifiers page but from what I can tell it doesn't shed light on whatever is happening with %*s or the %5.2f (not to mention the 3 apparent placeholders followed by 4 arguments) above?!?

    Read the article

  • Convert .net String object into base64 encoded string

    - by chester89
    I have a question, which Unicode encoding to use while encoding .NET string into base64? I know strings are UTF-16 encoded on Windows, so is my way of encoding is the right one? public static String ToBase64String(this String source) { return Convert.ToBase64String(Encoding.Unicode.GetBytes(source)); }

    Read the article

  • split a string based on pattern in java - capital letters and numbers

    - by rookie
    Hi all I have the following string "3/4Ton". I want to split it as -- word[1] = 3/4 and word[2] = Ton. Right now my piece of code looks like this:- Pattern p = Pattern.compile("[A-Z]{1}[a-z]+"); Matcher m = p.matcher(line); while(m.find()){ System.out.println("The word --> "+m.group()); } It carries out the needed task of splitting the string based on capital letters like:- String = MachineryInput word[1] = Machinery , word[2] = Input The only problem is it does not preserve, numbers or abbreviations or sequences of capital letters which are not meant to be separate words. Could some one help me out with my regular expression coding problem. Thanks in advance...

    Read the article

  • An analog of String.Join(string, string[]) for IEnumerable<T>

    - by abatishchev
    class String contains very useful method - String.Join(string, string[]). It creates a string from an array, separating each element of array with a symbol given. But general - it doesn't add a separator after the last element! I uses it for ASP.NET coding for separating with "<br />" or Environment.NewLine. So I want to add an empty row after each row in asp:Table. What method of IEnumerable<TableRow> can I use for the same functionality?

    Read the article

  • An analog of String.Join(string, string[]) for List<T> or other generic enumerable

    - by abatishchev
    class String contains very useful method - String.Join(string, string[]). It creates a string from an array, separating each element of array with a symbol given. But general - it doesn't add a separator after the last element! I uses it for ASP.NET coding for separating with "<br />" or Environment.NewLine. So I want to add an empty row after each row in asp:Table. What method of IEnumerable<TableRow> can I use for the same functionality?

    Read the article

  • How to convert string with double high/wide characters to normal string [VC++6]

    - by Shaitan00
    My application typically recieves a string in the following format: " Item $5.69 " Some contants I always expect: - the LENGHT always 20 characters - the start index of the text always [5] - and most importantly the index of the DECIMAL for the price always [14] In order to identify this string correctly I validate all the expected contants listed above .... Some of my clients have now started sending the string with Doube-High / Double-Wide values (pair of characters which represent a single readable character) similar to the following: " Item $x80x90.x81x91x82x92 " For testing I simply scan the string character-by-character, compare char[i] and char[i+1] and replace these pairs with their corresponding single character when a match is found (works fine) as follows: [Code] for (int i=0; i < sData.length(); i++) { char ch = sData[i] & 0xFF; char ch2 = sData[i+1] & 0xFF; if (ch == '\x80' && ch2 == '\x90') zData.replace("\x80\x90", "0"); else if (ch == '\x81' && ch2 == '\x91') zData.replace("\x81\x91", "1"); else if (ch == '\x82' && ch2 == '\x92') zData.replace("\x82\x92", "2"); ... ... ... } [/Code] But the result is something like this: " Item $5.69 " Notice how this no longer matches my expectation: the lenght is now 17 (instead of 20) due to the 3 conversions and the decimal is now at index 13 (instead of 14) due to the conversion of the "5" before the decimal point. Ideally I would like to convert the string to a normal readable format keeping the constants (length, index of text, index of decimal) at the same place (so the rest of my application is re-usable) ... or any other suggestion (I'm pretty much stuck with this)... Is there a STANDARD way of dealing with these type of characters? Any help would be greatly appreciated, I've been stuck on this for a while now ... Thanks,

    Read the article

  • Padding a string in Postgresql with rpad without truncating it

    - by dmoebius
    Using Postgresql 8.4, how can I right-pad a string with blanks without truncating it when it's too long? The problem is that rpad truncates the string when it is actually longer than number of characters to pad. Example: SELECT rpad('foo', 5); ==> 'foo ' -- fine SELECT rpad('foo', 2); ==> 'fo' -- not good, I want 'foo' instead. The shortest solution I found doesn't involve rpad at all: SELECT 'foo' || repeat(' ', 5-length('foo')); ==> 'foo ' -- fine SELECT 'foo' || repeat(' ', 2-length('foo')); ==> 'foo' -- fine, too but this looks ugly IMHO. Note that I don't actually select the string 'foo' of course, instead I select from a column: SELECT colname || repeat(' ', 30-length(colname)) FROM mytable WHERE ... Is there a more elegant solution?

    Read the article

  • Trim a string in C

    - by Orion Edwards
    Briefly: I'm after the equivalent of .NET's String.Trim in C using the win32 and standard C api (compiling with MSVC2008 so I have access to all the C++ stuff if needed, but I am just trying to trim a char*). Given that there is strchr, strtok, and all manner of other string functions, surely there should be a trim function, or one that can be repurposed... Thanks

    Read the article

  • Regarding Java String dollar to cents conversion

    - by arav
    I have a java string which has an dollar value and cents value after decimal points and starting with a + or - sign. I want to convert into cents and store it in a integer (it can have + or -). Also i need to check if the cents part (after decimal point) not more than 2 digits and throw an error message if exists example : String dollval= "12.23" ,"12","-0.09", "-99","-99.0", "-99.23","0.00" int dollint = 1223,12,-9,-99,-00,-9923,0

    Read the article

  • Sql Server string to date conversion

    - by JosephStyons
    I want to convert a string like this: '10/15/2008 10:06:32 PM' into the equivalent DATETIME value in Sql Server. In Oracle, I would say this: TO_DATE('10/15/2008 10:06:32 PM','MM/DD/YYYY HH:MI:SS AM') This question implies that I must parse the string into one of the standard formats, and then convert using one of those codes. That seems ludicrous for such a mundane operation. Is there an easier way?

    Read the article

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