string-manipulation

optimizing a php function that trims strings

Hi, i programmed this php function that takes any text/html string and trims it. For example: gen_string("Hello, how are you today?",10); Returns: Hello, how... The problem arises when the function string limit is the same as the position of a special character such as: á, ñ, etc... In which case: gen_string("Helló my friend",5); ...

Counting spaces infront of a String

Hello, Recently I asked this question: http://stackoverflow.com/questions/3199449/removing-up-to-4-spaces-from-a-string and it works just fine. I am interested however in counting the number of spaces I have removed as well. How can I do this? Count the number of spaces removed using this? stringArray[i] = stringArray[i].replaceFirst ...

Objective C string manipulation, peeking, adding to

Hi, I am trying to manipulate a string of open hours that is given to me. It is poorly formatted and I need to bring it up to the same standard as another piece of data from a different source. Mon-Wed 930-1700 Thu 900-1700 Fri 930-1700 Mon - Wed 930-1700 Thu 900-1700 Fri 930-1700 Mon - Thu 930-1600 Fri 930-1700 Mon - Wed 930-1700 Thu...

Buffer too small when copying a string using wcsncpy_s.

This C++ code is kind of lame, but I need to maintain it. I cannot seem to figure out a "buffer too small" problem. I am using Visual Studio 2010. I will come up with minimal code required to reproduce based on the values I see in the debugger. Sorry, I will not have tested the actual snippet itself. Also, since my system clipboard is "b...

Regular expression help - sum the numbers in a string?

Hi All, Not sure if this is the best approach but I have some string which represents the orientation of some blocks. For example '3V6V' means a row of 3 vertical blocks, and a row of 6 vertical blocks. '3V6V6V' means row of 3, 6, 6 all vertical. '4H4H4H4H' would be 4 rows of 4 horizontal blocks. i.e. every 2 characters constitutes a ro...

Help me translate Python code which replaces an extension in file name to C++.

I apologize if you know nothing about Python, however, the following snippet should be very readable to anyone. The only trick to watch out for - indexing a list with [-1] gives you the last element if there is one, or raises an exception. >>> fileName = 'TheFileName.Something.xMl' >>> fileNameList = fileName.split('.') >>> assert(len(f...

Java Quotation Matching

Hello all, I'm not sure if this is a regex question, but i need to be able to grab whats inside single qoutes, and surround them with something. For example: this is a 'test' of 'something' and 'I' 'really' want 'to' 'solve this' would turn into this is a ('test') of ('something') and ('I') ('really') want ('to') ('solve this') A...

How to produce a string of double-quote with emacs lisp?

I need to produce a string with emacs lisp, in which, there must contain double-quote '"'. By studying the string syntax of emacs lisp, I thought "\"" would represent such double-quote. But to my surprise, I the following expression (concat "\"") produced "\"" the '\' being not desired. Please teach me how I can produce a pure double...

24hr to 12hr time convert, insert character to string

This is sort of a secondary question to my question here but it was suggested split the questions up for a better response. I have individual lines of data like the following that a passed to the function separately. Mon-Wed 930-1700 Thu 900-1700 Fri 930-1700 Mon-Wed 930-1700 Thu 900-1700 Fri 930-1700 Sat 900-1200, Home Lending Sat ...

How Can i Fetch a Word of a String?

I have the following string: string path = "C:\Users\Username\Desktop\FileName.pdf"; I need to take off FileName.pdf and put in a string variable called fileName. The code has to be generic in a sense that anytime i get path, i start going from the end of the string down to the first backslash. I'm using C# ...

PHP regex for matching double and/or single quoted strings within in a string.

Hello, I'm working on a template class and I've an issue when trying to parse out a list of quoted strings from a string argument list. Take for example the string: $string = 'VAR_SELECTED, \'Hello m\'lady\', "null"'; I'm having a problem coming up with a regex that extracts the string "Hello m'lady" and "null". The closest I have go...

query for substring formation

I want to take the 01 part of a string abcd_01 using SQL. What should be the query for this, where the length before the _ varies? That is, it may be abcde_01 or ab_01. Basically, I want part after the _. Thanks. ...

PHP How to remove numbers like [3][2][4] from string using php

I have a text string that contain some references numbers like [3][2][4] or [1] or [5][7] can you please help me removing all numbers between brackets ex. [4] from that string using regular expressions Regex ? Thanks ...

Need help on this SQL...

Here is the question: +--------------+ Ships | +--------------+ Duke of north | ---------------+ Prince of Wales| ---------------+ Baltic | ---------------+ I need to replace all characters between the first and the last spaces (excluding these spaces) by symbols of an asterisk (*). The number of asterisks must be eq...

Fastest way to remove first char in a string

Say we have the following string string data= "/temp string"; If we want to remove the first character / we can do by alot of ways such as : data.Remove(0,1); data.TrimStart('/'); data.Substring(1); But .. really I don't know which one have the best algorithm and doing that faster .. Is there a one that is the best or all are the...

(Django) saving string to EmailField raises 'invalid literal for int() with base 10'

In my user's data edit form I have a boolean field, for adding/removing email from newsletter. I've written a custom save method for this form : def save(self, *args, **kwargs): mail = None if self.cleaned_data['inf_newsletter']: mail = NewsletterEmails(self.instance.user.email) mail.save() else: ...

Removing the first part of a concatenated string with Python

I have a string as follows CompilationStatistics_Compilation_StepList_Map_TimingUsage_ClockList_Clock_MinimumPeriod What would be the simplest way to remove the first part (CompilationStatistics_) or the last part (_MiniumuPeriod)? I think about using regular expression, but I expect there should a better way. m = re.search("{.+}_...

String concatenation within a javascript object

I'm sure there is a simple answer to this but I couldn't find it. I know how to concatenate a normal string in JavaScript but how would I do it within an object? I require this as I'm reading through an XML file and creating the HTML for a list of links. Each time I go through the loop I want to create a new <li> containing the link. ...

SQL Server String Manipulation Query

Hi guys I have a table with many URLS like www.topshop.com www.shopbop.co.uk http://www.magickingdom.net http://www.asos.co.uk UPDATE Needs to be able to handle this URL as well topshop.co.uk I want to be able to strip out the fluff such that it returns only topshop shopbop magickingdom asos Do I have to write a manual excepti...

Python: Using .format() on a Unicode-escaped string

I am using Python 2.6.5. My code requires the use of the "more than or equal to" sign. Here it goes: >>> s = u'\u2265' >>> print s >>> ≥ >>> print "{0}".format(s) Traceback (most recent call last): File "", line 1, in UnicodeEncodeError: 'ascii' codec can't encode character u'\u2265' in position 0: ordinal not in range(128)`...