You are currently browsing the category archive for the ‘programming’ category.

Unicode Characters converted to ASCII string

I hacking together a report today and discovered the Unicode text I received was actually in Unicode not ASCII.

Basically I have this:  こんにちは

And I want this:  

By using AscW(Char) you can convert a Unicode character into an integer value.  Add some delimiters to encode the string and you have a Unicode HTML Entity Reference.  It isn’t perfect, as AscW(Char) sometimes returns a negative number, which isn’t allowed, though this is an easy work around explained here.  It is used below.

Public Function UnicodeToAscii(sText As String) As String
  Dim x As Long, sAscii As String, ascval As Long

  If Len(sText) = 0 Then
    Exit Function
  End If

  sAscii = ""
  For x = 1 To Len(sText)
    ascval = AscW(Mid(sText, x, 1))
    If (ascval < 0) Then
      ascval = 65536 + ascval ' http://support.microsoft.com/kb/272138
    End If
    sAscii = sAscii & "&#" & ascval & ";"
  Next
  UnicodeToAscii = sAscii
End Function

Now lets go the other way: ASCII string to Unicode

Now I have this:  

And I want this:  こんにちは

I remembered that ChrW(int) will convert character codes to their associated character.  I really wasn’t in the mood to write parsing logic and test it, but luckily I came across a class which does this.  I ripped out the method I needed and it worked great in all it’s simplicity.  I have included this function below:

Public Function AsciiToUnicode(sText As String) As String
  Dim saText() As String, sChar As String
  Dim sFinal As String, saFinal() As String
  Dim x As Long, lPos As Long

  If Len(sText) = 0 Then
    Exit Function
  End If

  saText = Split(sText, ";") 'Unicode Chars are semicolon separated

  If UBound(saText) = 0 And InStr(1, sText, "&#") = 0 Then
    AsciiToUnicode = sText
    Exit Function
  End If

  ReDim saFinal(UBound(saText))

  For x = 0 To UBound(saText)
    lPos = InStr(1, saText(x), "&#", vbTextCompare)

    If lPos > 0 Then
      sChar = Mid$(saText(x), lPos + 2, Len(saText(x)) - (lPos + 1))

      If IsNumeric(sChar) Then
        If CLng(sChar) > 255 Then
          sChar = ChrW$(sChar)
        Else
          sChar = Chr$(sChar)
        End If
      End If

      saFinal(x) = Left$(saText(x), lPos - 1) & sChar
    ElseIf x < UBound(saText) Then
      saFinal(x) = saText(x) & ";" 'This Semicolon wasn't a Unicode Character
    Else
      saFinal(x) = saText(x)
    End If
  Next

  sFinal = Join(saFinal, "")
  AsciiToUnicode = sFinal

  Erase saText
  Erase saFinal
End Function

I didn’t always understand why you wouldn’t just want to work with the Unicode characters themselves.  Well is seems that not all applications treat Unicode the same way and the characters may be changed.  If you are storing and passing around a text representation of the characters there is no way for them to be misinterpreted.

One of the neatest things I like about this is that I can just put the text represented Unicode in a web page and the browser will automatically convert it to Unicode characters.  This is the reason I needed to use an image above to show what the text represented Unicode looks like.  If I just put the string there, it is converted by the browser when displayed.

If you have been to this post in the past, you have probably noticed that it has changed a bit.  That is because I had it all backwards! Yeah well it happens.  I said I want wanted to change Unicode characters to Ascii string, but the code actually was for the other way around.  Well I finally got around to fixing this and made sure that code worked before displaying it.  I hope this helps someone out there.

Advertisements

For months and months now I have asked myself, “Self, what language next, Ruby, Python, something else?” and has driven me crazy.  Someday I will ask myself why I spent so much time thinking about it instead of just digging in to something.  Well the real truth to that is time.  Sure I have spent time on the Ruby site going through browser-enabled 15 minute intro and some general reading.  It never really sticks until you throw together a couple of apps.

Over the last eight months I have been on a big web front end kick, getting myself up to speed on web display stuff like CSS, JavaScript, and jquery.  It’s been a lot of fun, but I really am not a good page designer, so besides reproducting current layouts there wasn’t a real lot for me to do.  

And there is always ASP.NET MVC which I have been following and learning off and on since August of 2008.  Having the web skills when putting together some learning MVC sites was really useful.  Don’t worry, I wont go on another, “I love MVC…”, rant.

Saturday morning I was in our local library with my two sons picking out movies reading some books, messing around and found myself at the card catalog computer screen.  Hey do you remember actual card catalogs, the rows and rows of drawers which contained cards of all the books in the library.  Here is one area computers help one-billion percent.  Anyway, I did my usual search for ASP.NET, came up with the same books as usual.  A 2008 book I had already checked out (and didn’t like too much) during my web learning, and some older stuff.  Oh hum I thought….

Than I had an idea and started typing

ruby programming

A match, wow a match and a recent book too.  I was was feeling a bit excited.  Okay, let’s try another

python programming

Ah, nothing on that one.  Well that settles it—right, wrong or indifferent, I will start with Ruby.  Well, I have always been leaning this way anyhow.  The exposure I have had, I have liked, now to come up with an app to put together.  Then of course if I get my arms around the language I will have to move on to Rails, and Iron Ruby (Uses .NET’s DLR).

Hey look, ASP.NET has made it’s first live-supported release!  This is great!

I have been using the MVC pattern for a good 8 months now and I just love it.  It just makes so much sence to the way I think. Sure there is a learning curve to get started with ASP.NET MVC, whatever, it’s worth the trip.

I read about it here first.  Phil Haack wrote about the release.
You can get the release from here.

Remember if you have a previous version of ASP.NET MVC loaded, you will have to unistall it first.  A short time ago, Phil Haack, Scott Hanselman, Rob Conery, and ScottGu release a FREE tutorial to MVC, as a fist “Chapter” to their upcomming book, ASP.NET MVC 1.0.

ASP.NET MVC 1.0

ASP.NET MVC 1.0

Just the other day I decided to sign up with dreamhost for SVN and web hosting.  This hosting service is setup really well.  They have one very reasonably priced plan, and charge for extras from there.  Not that I need any.  They are running an unlimmited storage and bandwidth special right now.  Normally 50G (not sure on bw);  5 MySql databases, unlimited email and shell/ftp users,unlimited mail, imap access, webmail client, etc., etc.  Truly full service hosting. You can setup a virtual private server for on $15 per month extra!

Programming support for PHP5, Perl, Python, Full Unix Shell (one of my favorite parts), Crontab access, Full CGI access, Ruby On Rails, SSI, CVS and SVN reopos, and they have mod_dav_svn installed!

Running on Debian Linux, friends have told me that they have had very little down time with the service.

You cannot go wrong with all they provide for the price they charge ($9/month?), easily the best Linux based hosting I have come across.  Only time will truly tell me how reliable the service is.  The word on the street is good!

http://dreamhost.com

Oh yeah, and they are a green hosting center 🙂

I am diving head-first into the world of .NET 3.5.  And not having the support of my employer, I am flying solo, using the Express versions of Visual studio.

I ordered this, and hoping it will be a promising reference for me.

Pro C# 2008 and the .NET 3.5 Platform, Fourth Edition (Windows.Net).

Update (10/23/2008):
Well truth be told the book is excellent, a very good reference to add to my collection.  It doesn’t have a lot of ASP.NET information in it and I really need help in this area.  See, simply, I am UI challenged.  When it comes to writing web front ends, forget it.  Sure I have done a good bit of web work, but most of it was hacking on stuff already put together.

No I wonder my next step.  Apress has two C# ASP.NET books and I am not sure which one to get.  There is a Pro book and a Beginners book.

Beginning ASP.NET 3.5 in C# 2008: From Novice to Professional, Second Edition (Beginning from Novice to Professional)

Pro ASP.NET 3.5 in C# 2008, Second Edition (Windows.Net)

They both have good ratings but I wonder if the Pro version will just be more information that I care about and may skip over some basic things I don’t understand about web UI design.  On the other hand the basic book may be too basic and not add any “meat” to its explainations.  I don’t learn as well if I don’t understand why something is doing what it is.  I guess it’s time for a trip to the bookstore and flip throuh some pages.  I wonder if my family will ever let me out to do that…

Not sure on the accuracy of these, but I needed this info, found it, and wanted somewhere to stick it.

File Ext: Content Type:
docm application/vnd.ms-word.document.macroEnabled.12
docx application/vnd.openxmlformats-officedocument.wordprocessingml.document
dotm application/vnd.ms-word.template.macroEnabled.12
dotx application/vnd.openxmlformats-officedocument.wordprocessingml.template
ppsm application/vnd.ms-powerpoint.slideshow.macroEnabled.12
ppsx application/vnd.openxmlformats-officedocument.presentationml.slideshow
pptm application/vnd.ms-powerpoint.presentation.macroEnabled.12
pptx application/vnd.openxmlformats-officedocument.presentationml.presentation
xlsb application/vnd.ms-excel.sheet.binary.macroEnabled.12
xlsm application/vnd.ms-excel.sheet.macroEnabled.12
xlsx application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
xps application/vnd.ms-xpsdocument

Thanks to:
Doug mahugh, on msdn blog

//Get response
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

StreamReader sr = new StreamReader(response.GetResponseStream());
result = sr.ReadToEnd();
sr.Close();
Console.WriteLine(result);

As I log into My Yahoo! account I am greeted with a message that a new updated version of My Yahoo! site is available as a beta site. Since Yahoo! usually lets you go back to the old version again, I thought I would check it out. Basically it has become the typical AJAX’d to hell big font “Web2.0” site. Fooy. I don’t get the new interfaces with all this Javascript, big-ass fonts, and bubbly edges, they are just such bloated pigs. The new font resolutions make it really difficult to use anything but a full-screened browser, which I hate to do. The UI is windowed for a reason. The My Yahoo! beta reminds me a lot of the new mail interface Yahoo! designed a few years ago. No I don’t use it either, it was just to slow and clunky of an interface back then, though I haven’t tried it again.  Another part that irked me is that many of the modules I had on My Yahoo! page no longer worked on the new site.  Why would you offer a new layout if many of the items which are used, aren’t available any longer?  I don’t get that.

FogCreek Software’s FogBugz has done the same thing with their latest release, 6.0. Changed to this really fat font and some other layout changes. I understand UI changes always take some time to get used to, but even after three weeks using the product, it still doesn’t feel natural. Funny, reading Joel Spolsky’s blog, when he returned to New York after his first demo tour for FogBugz 6.0 he himself the UI has been stripped down way to much and it’s just horrible. It happens, anyone in development knows it. At least he is being smart about it and re-doing it from step one.

I have to say that I am happy that so far Yahoo! hasn’t forced me into using their new interfaces for their products. I don’t think that I am that stubborn when it comes to changes, I just expect at least to have the same functionality that I did in a previous version. Don’t make me take two steps backwards in functionality when you introduce a new product.

I would really like to know why web designers are thinking this new larger font is the way to go on web pages? I am seeing it more and more, and I still find it less appealing and usable.

I have used Sourcegear’s Vault for about 3 years now at work. I have recently started a project on my own and, of course, want to use a SCM. I decided to try Perforce, since the product if free for two users and five work spaces. Well, I just didn’t get it, I figure I just not smart enough to use the product. I couldn’t even submit the intial load of the repository without having to read the manual. The one thing that really turned me off, it that I had to check out a file to edit it. When I forced to overwrite the file anyway, Perforce didn’t noticed that it changed. I am sure I wasn’t doing somthing properly, but these are issues I never had with Vault. I grew up in the world of CVS, where everyone has there own copy of the codebase and are responsible for incorporating the latest changes from the repository before checking in there changes. So you are probably asking why I just didn’t use Vault? Simple enough, I wanted to try something different. So I have, I am not that crazy about it, and I am going back to Vault, which by they way is free for a single user also. The one thing I will say about Perforce over Vault is that it seems much less system intensive and has less hardware requirements.

Twitter Updates

Error: Twitter did not respond. Please wait a few minutes and refresh this page.

Advertisements
%d bloggers like this: