Author Topic: IntSplit  (Read 2020 times)

0 Members and 1 Guest are viewing this topic.

Offline CurryWurst

  • Camper
  • ***
  • Posts: 265
    • Soldat Global Account System
IntSplit
« on: January 29, 2009, 04:03:19 pm »
Script Name: IntSplit
Script Description Splits a string into an array of integer
Author: Dual

Hosted by: http://soldatcentral.com/
Core Version: 2.6.3
Compile Test: Passed

The function IntSplit() splits a string representing integer values into an array of integers.
SOURCE determines the string to be splitted by the Delimiter.

Code: [Select]
function IntSplit(const SOURCE: string; Delimiter: string): array of integer;
var
  i, x, d: integer;
  s, b: string;
begin
  d:= length(Delimiter);
  i:= 1;
  SetArrayLength(Result, 1);
  while (i <= length(SOURCE)) do
  begin
    s:= Copy(SOURCE, i, d);
    if (s = Delimiter) then
    begin
      Inc(i, d)
      SetArrayLength(Result, x + 1);
      if (RegExpMatch('^-?\d+$', b)) then
      begin
        Result[x]:= StrToInt(b);
      end;
      b:= '';
      Inc(x, 1);
    end else
    begin
      b:= b + Copy(s, 1, 1);
      Inc(i, 1);
    end;
  end;
end;

Parameters:

SOURCE: string
String to be splitted into an array of integer.

Delimiter: string
Defines a string as split point.

Return Value:

Depending on the amount of delimiters the SOURCE string contains, the elements count of the integer array will increase.

Note:

IntSplit() will always return at least one array element. The function also ignores non-integer values by skipping them.
Integer values with a negative (-) algebraic sign count as legal integer values.



(Size 655 B)
- http://soldatcentral.com/index.php?page=script&f=95 -


** Script hosted by Soldat Central! Please visit the author's script page and Rate this script **
« Last Edit: February 08, 2009, 10:52:42 am by Markus Quär »
Soldat Global Account System: #soldat.sgas @ quakenet

Offline Gizd

  • Flagrunner
  • ****
  • Posts: 586
  • (Re)tired
    • Eat-this! community site
Re: IXSplit
« Reply #1 on: January 30, 2009, 06:59:37 am »

Offline chutem

  • Veteran
  • *****
  • Posts: 1119
Re: IXSplit
« Reply #2 on: January 30, 2009, 03:18:54 pm »
^ you think he doesn't know about that?

Look at his script name IXSplit. i.e Integer-XSplit, which is what it does, splits a string into an array of integer...
1NK3FbdNtH6jNH4dc1fzuvd4ruVdMQABvs

Offline CurryWurst

  • Camper
  • ***
  • Posts: 265
    • Soldat Global Account System
Re: IXSplit
« Reply #3 on: January 30, 2009, 03:25:31 pm »
Look at his script name IXSplit. i.e Integer-XSplit, which is what it does, splits a string into an array of integer...

Exactly :D
Soldat Global Account System: #soldat.sgas @ quakenet

Offline Gizd

  • Flagrunner
  • ****
  • Posts: 586
  • (Re)tired
    • Eat-this! community site
Re: IXSplit
« Reply #4 on: January 31, 2009, 05:23:09 am »
Oh, nice func then :)

Offline frosty

  • Flagrunner
  • ****
  • Posts: 601
  • Uber Desert Eagle ^^
Re: IXSplit
« Reply #5 on: February 02, 2009, 11:30:11 pm »
how would i use this? could someone give an example plz?
check out my server! click here

If at first you don't succeed, Improvise! :D

Offline iDante

  • Veteran
  • *****
  • Posts: 1967
Re: IXSplit
« Reply #6 on: February 02, 2009, 11:34:14 pm »
how would i use this? could someone give an example plz?
It's for scripters to use. Say, you loop through every player and add their score to a string with a space in between. Later you can use this script to split it into an array of integers.

Handy to have.

Offline CurryWurst

  • Camper
  • ***
  • Posts: 265
    • Soldat Global Account System
Re: IntSplit
« Reply #7 on: February 05, 2009, 09:01:22 am »
Function renamed as IntSplit to avoid name confusion with XSplit.
Soldat Global Account System: #soldat.sgas @ quakenet