| Home Page | Recent Changes

Nomad/WUtils

What is wUtils?

wString

InStrPlus()

static final function int InStrPlus( coerce string HayStack, coerce string Needle, optional int Start )
{
     local int i;

     for ( i = Start; i < Len( HayStack ); i++ )
          if ( Mid( HayStack, i, 1 ) == Needle )
               break;

     return i;
}

Mychaeel: I'm afraid this is a very slow and inefficient way to implement this function; besides, it'll only search for single-character "Needle"s. Better do something like InStrFrom on UT2003/Suggestions.

nomad: Your version is a lot better, this is something I used in Deus Ex ages ago.

ReplaceOption()

nomad: Not sure wheather or not this should be added to wUtils. It allows you to quickly change a value in the Options string used in Login and PostLogin.

static function bool ReplaceOption( out string Options, string Key, string NewValue, optional out string OldValue, optional bool bAddIfMissing )
{
     local array<string> OptionsArray;
     local int i;
     local string   CurrentKey, CurrentValue;
     local bool     bReplaced;
     bReplaced = false;

     // Need to strip the first ? from Options otherwise Split doesn't work
     if ( Left( Options, 1 ) == "?" )
          Options = Right( Options, Len( Options ) - 1 );

     Split( Options, "?", OptionsArray );

     for ( i = 0; i < OptionsArray.Length; i++ ) {
          Divide( OptionsArray[i], "=", CurrentKey, CurrentValue );

          if ( CurrentKey ~= Key ) {
               OldValue = CurrentValue;
               OptionsArray[i] = CurrentKey$"="$NewValue;
               bReplaced = true;
               log( "ReplaceOption() :: Replaced ["$CurrentKey$"] Old = "$OldValue$", new = "$NewValue, 'wUtils' );
          }
     }

     if ( !bReplaced && bAddIfMissing )
          OptionsArray[OptionsArray.Length] = Key$"="$NewValue;

     Options = "?"$Join( OptionsArray, "?", Options );
     return bReplaced;
}

The Unreal Engine Documentation Site

Wiki Community

Topic Categories

Recent Changes

Offline Wiki

Unreal Engine

Console Commands

Terminology

FAQs

Help Desk

Mapping Topics

Mapping Lessons

UnrealEd Interface

UnrealScript Topics

UnrealScript Lessons

Making Mods

Class Tree

Modeling Topics

Chongqing Page

Log In