Extract email address with SQL UDF
RETURNS @Results TABLE (Items nvarchar(4000))
AS
DECLARE @INDEX INT
DECLARE @SLICE nvarchar(4000)
— HAVE TO SET TO 1 SO IT DOESNT EQUAL Z
— ERO FIRST TIME IN LOOP
SELECT @INDEX = 1
— following line added 10/06/04 as null
— values cause issues
IF @String IS NULL RETURN
WHILE @INDEX !=0
— GET THE INDEX OF THE FIRST OCCURENCE OF THE SPLIT CHARACTER
SELECT @INDEX = CHARINDEX(@Delimiter,@STRING)
— NOW PUSH EVERYTHING TO THE LEFT OF IT INTO THE SLICE VARIABLE
IF @INDEX !=0
SELECT @SLICE = LEFT(@STRING,@INDEX – 1)
ELSE
SELECT @SLICE = @STRING
— PUT THE ITEM INTO THE RESULTS SET
INSERT INTO @Results(Items) VALUES(@SLICE)
— CHOP THE ITEM REMOVED OFF THE MAIN STRING
SELECT @STRING = RIGHT(@STRING,LEN(@STRING) – @INDEX)
— BREAK OUT IF WE ARE DONE
IF LEN(@STRING) = 0 BREAK
END
RETURN
END
( @TextContainingEmail varchar(1000) )
RETURNS varchar(1000)
AS
BEGIN
declare @retval varchar(1000)
select top 1 @retval=items from dbo.split(@TextContainingEmail,’ ‘)
where items like ‘%@%’
return @retval
END
Export Google Search Results to CSV
{
GoogleSearchService.GoogleSearchService gss =
new GoogleSearchService.GoogleSearchService(); string CSV = ""; try{
for(int i=170;i<10000;i+=10){
GoogleSearchService.GoogleSearchResult gsr = gss.doGoogleSearch("L3Pyyh5QFHKU740wXUu0/aBu17loGATB",SearchString,0,10,
false,"",false,"","",""); foreach(GoogleSearchService.ResultElement reSearch in gsr.resultElements){
CSV += reSearch.title.Replace(",","").Replace("n","") + ",";
CSV += reSearch.snippet.Replace(",","").Replace("n","") + ",";
CSV += reSearch.URL.Replace(",","").Replace("n","") + "n";
}
Debug.Write("Progress:" + i.ToString());
}
}
catch(Exception ex){
Debug.Write(ex.ToString());
}
FileStream fsOut =
new FileStream(FileName,FileMode.Create);StreamWriter swOut =
new StreamWriter(fsOut);swOut.Write(CSV);
fsOut.Close();
}
Writing a C# Application without a user interface
public
System.Timers.Timer tmrPoll = new System.Timers.Timer();[STAThread]
static void Main(){
VoiceMailMain vmmInstance =
new VoiceMailMain();vmmInstance.tmrPoll.Enabled =
true;vmmInstance.tmrPoll.Interval = 5000;
vmmInstance.tmrPoll.Elapsed +=
newSystem.Timers.ElapsedEventHandler(vmmInstance.tmrPoll_Tick);
System.Threading.Thread.CurrentThread.Suspend();
}
public
void tmrPoll_Tick(object sender, System.Timers.ElapsedEventArgs e){ … and magic happens … }
Simple when you know how!
No mapping between account names and security IDs
Uploading a file via a web service
string
strPath = HttpContext.Current.Request.ServerVariables["APPL_PHYSICAL_PATH"].ToString(); string strFileName = (Guid.NewGuid()).ToString()+".wav";FileStream fsWave =
new FileStream(strPath + strFileName,FileMode.Create);fsWave.Write(WaveData,0,WaveData.Length);
fsWave.Close();
Where WaveData was my Byte array.
Then when consuming this service, from an ASP.NET page, I used this code
HttpPostedFile hpfWave =
this.AudioFile.PostedFile; int intFileLen = hpfWave.ContentLength; byte[] bWaveData = new byte[intFileLen];hpfWave.InputStream.Read(bWaveData, 0, intFileLen);
strMessage = vmWebService.UploadAudio(bWaveData);
Where AudioFile is my Input type=file on the web page, and vmWebService was my webservice.
If you’re interested in knowing where this is leading, check out www.sms-txt.co.uk in a few days!
SQL performance: Nested select statements.
Charset reverting to Windows standard
Differences between CHOICE command in Batch files
IF ERRORLEVEL == 3 GOTO LIVE
IF ERRORLEVEL == 2 GOTO BACKUP
IF ERRORLEVEL == 1 GOTO LOCAL
EXIT
set /p choice=Please choose a menu option.
if not ‘%choice%’==” set choice=%choice:~0,1%
if ‘%choice%’==’1’ goto LOCAL
if ‘%choice%’==’2’ goto BACKUP
if ‘%choice%’==’3’ goto LIVE
EXIT
Google Toolbar buttons… second attempt
http://toolbar.google.com/buttons/add?url=http%3A%2F%2Fwww.webtropy.com%2fw%2fbuymusiccd.xml
http://toolbar.google.com/buttons/add?url=http%3A%2F%2Fwww.webtropy.com%2fw%2ffindpeoplefreecouk.xml
Transparent Localisation
public static string getGetSiteCulture()
{
string strUrl = System.Web.HttpContext.Current.Request.Url.ToString().ToLower();
string strCulture = "en-GB";
if (strUrl.IndexOf("mensajetexto")!=-1) {strCulture = "es-ES";}
if (strUrl.IndexOf("handyspruche")!=-1) {strCulture = "de-DE";}
if (strUrl.IndexOf("envoyezsms")!=-1){strCulture = "fr-FR";}
return strCulture;
}
Then I have 4 different Resource files, strings.es-ES.resx, strings.en-GB.resx etc.
public static string Translate(string ID)
{
rmTranslations.IgnoreCase =
true;
string strTranslation ="";
Thread.CurrentThread.CurrentCulture =
new CultureInfo(getGetSiteCulture());
Thread.CurrentThread.CurrentUICulture =
new CultureInfo(getGetSiteCulture());
try
{strTranslation= rmTranslations.GetString(ID);}
catch{
throw new Exception(ID + " not found");
}
return strTranslation;
}
Then in place of static text, I put Translations.Translate("Whatever")