Quantcast

Jump to content

» «
Photo

Questions about C#

5 replies to this topic
Bad.boy!
  • Bad.boy!

    SA modder

  • Feroci
  • Joined: 20 Jun 2010
  • Netherlands

#1

Posted 09 April 2012 - 09:47 PM Edited by Bad.boy!, 10 April 2012 - 08:47 AM.

Does anyone know how to make global strings in C#? I know you can make something like this:
CODE
public static class Globals
   {
       public const string FCarcol = "example";
   }


But that doesn't allow me to write something new.

And how to break up a string like this in seperate parts:
CODE
supergt, supergt, car,  SUPERGT,  SUPER,  VEH@LOW, VEH@LOW_INFERNUS, 100, 999,  0.2286, 0.2286,  0, 2, 1.0 ,0, -

nightwalker83
  • nightwalker83

    Don't mind me

  • Members
  • Joined: 10 Oct 2004

#2

Posted 10 April 2012 - 12:33 AM

Question like this should be in the modding section I will request it moved.

Bad.boy!
  • Bad.boy!

    SA modder

  • Feroci
  • Joined: 20 Jun 2010
  • Netherlands

#3

Posted 10 April 2012 - 08:19 AM Edited by Bad.boy!, 10 April 2012 - 08:47 AM.

But it isn't a GTA mod. It's a windows console aplication. And my questions have nothing to do with GTA modding.
QUOTE
Does anyone know how to make global strings in C#?
And how to break up a string like this in seperate parts:


EDIT:
Found it btw
CODE
public static class Globals
   {
       public static string FCarcol
       {
           get
           {
               return FCarcol;
           }
           set
           {
               FCarcol = value;
           }
       }

       public static string FHandling
       {
           get
           {
               return FHandling;
           }
           set
           {
               FHandling = value;
           }
       }

       public static string FVehicle
       {
           get
           {
               return FVehicle;
           }
           set
           {
               FVehicle = value;
           }
       }
   }


CODE
string FCarcol = Globals.FCarcol;
           string FHandling = Globals.FHandling;
           string FVehicle = Globals.FVehicle;
           string[] Cline = Regex.Split(FCarcol, " ");

Barguast
  • Barguast

    Thy next foe is...

  • Andolini Mafia Family
  • Joined: 27 Jul 2002

#4

Posted 10 April 2012 - 11:20 PM

Those properties call themselves. You'll get stack overflows. A simple global string can be declared with;

public static string Str;

Or

public static string Str { get; set; }

Also, you can use string.Split rather than the RegEx method.

(on my phone, so sorry for bad formatting)

Bad.boy!
  • Bad.boy!

    SA modder

  • Feroci
  • Joined: 20 Jun 2010
  • Netherlands

#5

Posted 11 April 2012 - 05:22 PM Edited by Bad.boy!, 11 April 2012 - 06:49 PM.

Thanks for the help.

Do you also happen to know how to enter the location of a file, because when I type C:/Users for example the code can't find the location (as a string).

Nevermind

vincelegard
  • vincelegard

    Player Hater

  • Members
  • Joined: 24 Jun 2012

#6

Posted 24 June 2012 - 06:07 PM

split function


//declare a string array
string[] strArr = null;

str = "upergt, supergt, car, SUPERGT, SUPER, VEH@LOW, VEH@LOW_INFERNUS, 100, 999, 0.2286, 0.2286, 0, 2, 1.0 ,0, -"
char[] splitchar = { ',' };
strArr = str.Split(splitchar);

from strArr you can retrieve each string

source : http://csharp.net-in...tring-split.htm

legard.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users