string

Python string.replace() not replacing characters

Some background information: We have an ancient web-based document database system where I work, almost entirely consisting of MS Office documents with the "normal" extensions (.doc, .xls, .ppt). They are all named based on some sort of arbitrary ID number (i.e. 1245.doc). We're switching to SharePoint and I need to rename all of these f...

.NET / C# String Reference in Code Behind Not Loading Updated Value

I seem to have run into a strange issue whereby a string reference is not loading an updated value. In short, I've replaced a DLL file (App_Code.dll) that contains a bunch of page titles (think HTML Page Titles), but the values aren't being updated when referenced from other DLL's. Here's a code snippet from a codebehind of a sample pa...

Extension method for logging. A good idea?

What are, in your opinion, the pros/cons of the following extension method? static class Log { public static string AddToLog(this string input) { Console.WriteLine(input); return input; } public static string AddToLog(this string input, string format) { Console.WriteLine(format, input); ...

Bug: Null pointer deference of String

Hi, The test code below leads to a "null pointer deference" bug on a String Array(on line 6). This leads to a NullPointerException. public class TestString { public static void main (String args[]) { String test [] = null; for (int i =0; i < 5; i++) { String testName = "sony" + i; test [k] = testName; } } } -- How do I fix this? ...

String Usage in java

Consider am assigning the URL in the code below to a string, say String link = "http://www.topix.com/rss/city/ellensburg-wa"; How should I use the string in the below code instead of the URL itself. Note: am a beginner in java stmt.executeQuery("select url from urls where url='http://www.topix.com/rss/city/ellensburg-wa'"); stmt...

String Catenation in Python

I have this code: filenames=["file1","FILE2","file3","fiLe4"] def alignfilenames(): #build a string that can be used to add labels to the R variables. #format goal: suffixes=c(".fileA",".fileB") filestring='suffixes=c(".' for filename in filenames: filestring=filestring+str(filename)+'",".' print filestrin...

How can I create a string of random characters (as for a password...)?

I've written some code to generate a sequence of random characters, but it does not: byte[] sbytes = { 1, 0, 1, 0, 1 }; String sstring; System.Random r = new System.Random(); r.NextBytes(sbytes); sstring = Convert.ToBase64String(sbytes); sstring = Path.GetRandomFileName(); sstri...

python target string key count invalid syntax

Hi Why am i getting an "invalid syntax" when i run below code. Python 2.7 from string import * def countSubStringMatch(target,key): counter=0 fsi=0 #fsi=find string index while fsi<len(target): fsi=dna.find(key,fsi) if fsi!=-1: counter+=1 else: counter=0 fsi=...

GAE Datastore - Reduce Cursor String (base 64) Length

Currently, I'm when passing around a cursor string in a URL, and it looks very ugly. I was wondering if there was a way to shorten these? I was thinking I could encode it & decode it somehow, but I don't really know where to start looking for information on this. The cursor string is a base 64 encoded string. Any way to shorten it witho...

Need to create a function in sql to find a string

Hi guys, I am trying to write a function which can tell me whether there is something after second ; in the string or not.For example: the sample string is "2:00AM;3:00PM;". So the function in this case needs to return false. ...

How do I disable quoted identifiers when scripting out SQL Server database objects in Visual Studio?

Hi, I'm using Visual Studio 2005 to script out a database so that I can put it in subversion. Now one complaint that I have is that it puts my stored procedure code in a single literal string, like in the example. below. /****** Object: StoredProcedure [dbo].[MyStoredProc] Script Date: 08/19/2010 16:40:14 ******/ SET ANSI_NULLS ON...

Shortest C code to reverse a string..

Not counting the function signature (just the body) can anybody produce C code shorter than this function that will reverse a string and return the result as a pointer to the reversed string.. (not using a string reverse library function either)? char * reverse_str(char * s) { char c,*f=s,*p=s;while(*p)p++;while(--p>s){c=*p;*p=*s...

To remove duplicate word in a string in php

I want to remove duplicate words in a string. For example: $str="oneone"; (without spaces) I want to remove duplicates and display as one. Can anyone suggest me a solution? ...

Why doesn't my trim function work?

void trim(string &str) { string::iterator it = str.begin(); string::iterator end = str.end() - 1; // trim at the starting for(; it != str.end() && isspace(*it); it++) ; str.replace(str.begin(), it, ""); // trim at the end for(; end >= str.begin() && isspace(*end); end--) ; str.replace(str...

How to insert a string in SQLite database without conversion ?

The table: CREATE TABLE configuration(Key STRING, Value STRING, PRIMARY KEY (Key) ); Here is what I tried: insert into configuration(Key,Value) values(42,cast('0042' as text)); Here is the dump: INSERT INTO "configuration" VALUES(42,42); What I wanted: INSERT INTO "configuration" VALUES(42,'0042'); ...

How to refer to "\" sign in python string

I have problem with refering to special symbol in string: I have: path='C:\dir\dir1\dir2\filename.doc' and I want filename. When I try: filename=path[path.rfind("\"):-4] then interpreter says it's an error line right from "\" since is treated as a comment. ...

How to convert string to array?

I need to convert string "name1", "b", "2", "name2", "c", "3", "name3", "b", "2", .... to an array like $arr[0]['name'] = "name1"; $arr[0]['char'] = "b"; $arr[0]['qnt'] = "2"; $arr[1]['name'] = "name2"; $arr[1]['char'] = "c"; $arr[1]['qnt'] = "3"; $arr[2]['name'] = "name3"; $arr[2]['char'] = "b"; $arr[2]['qnt'] = "2"; I used expl...

String allocation trouble with 'new'

When in doubt, turn to Stackoverflow... I'm having a problem with string allocation. My goal is to store n length of a passed quoted string. I check m_p for null because I think in debug mode MS likes to set the address to 0xcccccccc instead of 0x00000000. I passed 1 into length. But when I allocate it using new, I'm getting about 15 ...

PHP Regular Expression to match define() function

Hi people I'm doing a translation of php script and want to gain some time by doing some automatization The file contains very large number of lines like these define('LNG_NewsletterNameIsNotValid', 'Email Campaign name is not Valid'); define('LNG_UnableToCreateNewsletter', 'Unable to create an Campaña de Email'); define('LNG_HLP_Newsle...

string double quotes replace with empty in c#

I have string. There are no items to show in this view of the "Personal Documents" then assign to string str variable string str ="There are no items to show in this view of the \"Personal Documents\" library" Now planning to replace "\" and make it to actual string to str object. I tried below, but did not worked str = str.Repl...