Buiding a Resource String File

Hi, I'm a bit new to C#, comming from a delphi environment, but have been through quite a numerous amount of tutorials and have learnt a good amount. But for now, i have the issue of trying to figure out how to make a resource string file in C# and use it.

Second Question - How do i use ansi strings in C#.  Such as 32 for space and 13 for enter and the such



Answer this question

Buiding a Resource String File

  • Philip Quirke

    Ok, thank you, i should be able to work with that., But about the first question about building a resource file - i'm not using Visual Studio, so it won't be that simple for me.  I still need to figure that one out.


  • zybernau

    Ok. I'm using Borland C# Builder. I don't see anywhere to build a new resource file. Even if you have to point me to a place where they actually teach how to build one from scratch, that is fine by me.


  • Cory6132

    Hello All.

    Netmaster0000:

    What compiler are you using I would think that including a string resource file would depend on the compiler. Look into the command line arguments and/or switches for your compiler to see how it compiles resource files.



  • niallhannon

    Hello All.

    Netmaster0000:

    Well, I definitely recommend Visual Studio. When I first started writing code for Windows, I did everything the hard way: piles of header files and #include directives, gobs of pointers, and all calls straight into the Win32 API.

    And yeah, the code that I wrote was lickety-split fast (when it worked ). And, if I managed to stay out of the runtime libraries, it was pretty small. But, then again, it wouldn't be able to do much.

    Then I got my hands on the VS C# Express Edition and after about 3 minutes, I decided to Hell with all of that! Aside from the particulars of C# and .NET, the VS IDE saves a ton of effort and time. It only took me about a month to decide to pony up the cash for the Standard version. Not because the Express version is no good, but because the Standard version is that much better.

    And as far as performance, if you're counting the CPU cycles, you might be able to tell the difference, but Elroy P. User sure can't. Now, having said that, if you want to talk about system code, then you still need to be right next to the machine, and that's not what .NET was designed to do, so yeah, there are still better ways of doing that. Personally, I think the best thing about .NET is that it keeps people (like me) the hell out of the operating system that have no business there.

    Believe me, if you're going to code against .NET and/or use C#, then Visual Studio is the way to go.

    HTH.



  • .neo

    Hello All.

    Netmaster0000:

    If you are developing in VS then adding a resource file is trivial. Simply go to the "Project" menu, select "Add new item", and select "new Resources file". You can then reference the strings as a strong type in your code, like

    string varname = Strings.ThisString;

    If you are building a Windows Forms app, the IDE includes a default resources file under the Properties section of the assembly. You can reference any resources from there in your code like

    string varname = AppNamespace.Properties.Resources.ThisString;

    On your second question, I presume you are referring to ASCII character codes, and their corresponding char values Well, that's much easier to do in VB, but here's a tiny snipped that shows one way:

    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace ConsoleApplication1

    {
    class Program
    {

    static void Main(string[] args)
    {

    Encoding enc = Encoding.ASCII;
    byte[] bytes = new byte[1];
    bytes[0] = 32;
    Console.Write(enc.GetChars(bytes));
    Console.WriteLine("that's a space");
    Console.ReadLine();
    }
    }
    }

    You have to set the code page to ASCII and then translate back and forth between numeric and char values.

    HTH



  • R.Tutus

    Hello All.

    Netmaster0000:

    I'm sorry but I have no idea about Borland C# Builder. You might try and see if you can find any user forums or newsgroups on the Web, and post this question there. As this is an MSDN forum, I would imagine that most folks around here use VS in one form or another.

    Do you mind if I ask why you are using Borland I only ask because, if possible, I would recommend moving to some form of Visual Studio. As I say, knowing nothing about Borland, I don't know what the level of support is in that develper community, but I can say for certain that the level of engagement on these forums is excellent.

    HTH



  • DC Ross

    Well, no particular reason for using Borland. I will use whatever compiles C#. Since the majority of my code is more focused on building generic libraries nothing in my code is specific to the compiler use, this is why i was asking if there's even a way i could build the resource file from scratch, because most likely a set of them will be built once, and used form there on out.


  • ar_pad

    Ok. No prob....but it still doesn't solve my resource file issue. No worries, i'll use some sort of work around for now, then go back to that sometime in the future.


  • David Avsajanishvili

    Hello All.

    Netmaster0000:

    I know that it is much simpler in VB, but everything I have done in C# has been strictly Unicode, so I'm probably not the best person to ask if there's an easier way in C#.

    Although, given the architecture of the CLR and the .NET Framework, together with the VS IDE, the functionality in VB for string and character manipulation should be readily available to anyone developing in C#.

    Something like this:

    using System;
    using System.Collections.Generic;
    using System.Text;
    using Microsoft.VisualBasic;

    namespace ConsoleApplication1
    {

    class Program
    {

    static void Main(string[] args)
    {
    int code = Strings.Asc('A');
    Console.WriteLine("This is the ASCII code: {0}",code);
    char letter = Strings.Chr(code);
    Console.WriteLine("This is the character: {0}",letter);
    Console.ReadLine();
    }
    }
    }

    The Asc() and Chr() methods are accessed by referring to the "Strings" module of the VB runtime library, referenced in the assembly and made visible by the "using Microsoft.VisualBasic" statement. So, the fully-qualified name would be Microsoft.VisualBasic.Strings.Asc() / Chr().

    HTH.



  • raghu_grdr

    Thank you, one last question, is there a simpler way to use ASCII, why, because it is intended to be concatenated with an existing string: for e.g.

    in delphi i would do
    const
    _rsDefaulMessage='Your account is currently disabled. '+#13+'Please contact your administrator.';

    and that constant would out put the string as one text, but with the return character in place of the ascii code for 13. Is such an approach, or even similiar method possible in c#


  • Buiding a Resource String File