string

Insert Something Every X Number of Characters Without Regex

In this question, the asker requests a solution that would insert a space every x number of characters. The answers both involve using a regular expression. How might you achieve this without a regex? Here's what I came up with, but it's a bit of a mouthful. Any more concise solutions? string = "12345678123456781234567812345678" new_st...

Where can I find the implementation for std::string

I am looking for the code for the c++ string class. What header is it implemented in? ...

Splitting a hex string into a list in Python - How?

If I have this string: hexstring = '001122334455' How can I split that into a list so the result is: hexlist = ['00', '11', '22', '33', '44', '55'] I can't think of a nice, pythonic way to do this :/ ...

Use of a deprecated module 'string'

Hi all. I just ran pylint on my code and it shows up this message: Uses of a deprecated module 'string' I am using the module string for join / split mainly. >>> names = ['Pulp', 'Fiction'] >>> import string >>> fullname = string.join(names) >>> print fullname Pulp Fiction Above is an example. In my code I have to make use of split...

Code golf: "Color highlighting" of repeated text

(Thanks to greg0ire below for helping with key concepts) The challenge: Build a program that finds all substrings and "tags" them with color attributes (effectively highlighting them in XML). The rules: This should only be done for substrings of length 2 or more. Substrings are just strings of consecutive characters, which may inc...

How to replace multiple %tags% in a string with PHP.

What is the best way of replacing a set of short tags in a PHP string, example: $return = "Hello %name%, thank you for your interest in the %product_name%. %representative_name% will contact you shortly!"; Where I would define that %name% is a certain string, from an array or an object such as: $object->name; $object->product_name; ...

how to show chinese word , not unicode word.

this is my code: from whoosh.analysis import RegexAnalyzer rex = RegexAnalyzer(re.compile(ur"([\u4e00-\u9fa5])|(\w+(\.?\w+)*)")) a=[(token.text) for token in rex(u"hi 中 000 中文测试中文 there 3.141 big-time under_score")] self.render_template('index.html',{'a':a}) and it show this on the web page: [u'hi', u'\u4e2d', u'000', u'...

Tool to convert code into a string?

I have found myself having to turn a chunk of Lua code into a string so it can be run as a proper Lua chunk. Writing code like that is not too difficult, but it's time consuming and prone to minor errors that result in lost development time and patience. Is there any tool/filter capable of taking a piece of runnable code and turning it ...

Ruby String parsing like how rails parses routes (with :symbols)

I'm trying to parse out some log files with ruby. I have plenty of experience with regexes but the other day I was using rails routes and thought that might be a really neat way to parse out these log files because it would be incredibly easy to understand the parser. Regex, on the other hand, takes several minutes for most people to d...

Split a string in jquery

How to split these strings in jquery? Mode1 2Level I want to get only the numbers from the above two strings in jquery... The strings may be Mode11,Mode111,22Level,222Level etc the characters Mode and Level wont change... ...

Split string with quotes, reusing method that parses arguments to main

Hi there, in small program I'm writing, I have to parse a line of user input. Basically what needs to be done is to split the line into an array of strings in the same way as is done with the arguments to main(), ie I'm looking for something like this: String[] splitArgs(String cmdLine); I just wonder, if the main methods' arguments ...

Enumerable LINQ extensions are hidden on strings... why and how ?

Possible Duplicate: Why doesnt VS 2008 display extension methods in Intellisense for String class Hi all. Yesterday I noticed that Enumerable LINQ exstensions are hidden on strings (I mean hidden from the intellisense). We all know string is an IEnumerable<char>, so automatically it should get Enumerable extensions, and actu...

decomposing a string into known patterns

Here's the python list of strings: patterns = [ "KBKKB", "BBBK", "BKB", "KBBB", "KBB", "BKBB", "BBKB", "KKBKB", "BKBK", "KBKB", "KBKBK", "BBK", "BB", "BKKB", "BBB", "KBBK", "BKKBK", "KB", "KBKBK", "KKBKKB", "KBK", "BBKBK", "BBBB", "BK", "KKBKBK", "KBBKB", "BBKKB", "KKKKBB", "KKB" ] I have an input string that consist of K and B only of...

Most used words in text with php

I found the code below on stackoverflow and it works well in finding the most common words in a string. But can I exclude the counting on common words like "a, if, you, have, etc"? Or would I have to remove the elements after counting? How would I do this? Thanks in advance. <?php $text = "A very nice to tot to text. Something nice to ...

.NET Application Settings -> setting the null string

What should I type (in both cases) in my app.config's applicationSettings section so that, when I read Settings, I can get the following: Settings.Default.FooString == null Settings.Default.FooString == string.Empty ? I guess there is no way to achieve both situations, or am I missing something? Diffrerenciating whether string valu...

Given this string (with '\n') how can I strip it from all the returns?

Here's the string: \n\n\t\thttp://www.linkedin.com/in/ckenworthy\n\n\t How can I strip everything so I only end up with: http://www.linkedin.com/in/ckenworthy I've tried the following: string value = doc.XPathSelectElement("/ipb/profile/contactinformation/contact[title/text() = 'LinkedIn']/value").Value; value = va...

Formatting String into MYSQL time

Ok, So i have a script that reads in a csv file and in there is a time that is formatted in the traditional HH:MM am/pm. I need to convert that into the mysql standard time format (HH:MM:SS). This is what i have so far and it works $schedule[$row]["TIME"] = date("H:i:s", strtotime($data[4])) the problem is, if the input is formatted...

How to print vertically aligned text

I want to print an output of the following format in a file.. 1 Introduction 1 1.1 Scope 1 1.2 Relevance 1 1.2.1 Advantages 1 1.2.1.1 Economic ...

How can you parse the string which has a text qualifier

Hello, How can I parse a String str = "abc, \"def,ghi\""; such that I get the output as String[] strs = {"abc", "\"def,ghi\""} i.e. an array of length 2. Should I use regular expression or Is there any method in java api or anyother opensource project which let me do this? Edited To give context about the problem, I am reading...

Bool Variable and string value compare in C#

Hello. If I declared a bool isTrue = false; // init it to false and I can get the value from a string strVal = T; // I assumed it is the TRUE value I heard it is not a good code style to compare string in C# like if (isTrue.tostring() == strVal) {}. Some time, I covert the the string variable to enum then I can compare it more conv...