Announcement

Collapse
No announcement yet.

[User Input] How to remove 1 character from the end of a var string

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    [User Input] How to remove 1 character from the end of a var string

    Dear Community,

    This might be utterly basic to some of you but I could not find any documentation on how to do this for quite awhile, so I decided to write something up for others who might have this question!

    ~~~

    How to Remove 1 Character From End of Variable Length String


    I finally found this page: http://udn.epicgames.com/Three/Strin...ealScript.html

    This explains string functions!

    Here is the function I wrote to remove one character from a string each time BackSpace is pressed.

    I use this for my in-game file system.

    Code:
    //global var
    var string fileroot;
    
    function backSpacePressed(){
       if (len(fileroot) == 0) return;
       else if (len(fileroot) == 1) {
    	fileroot = "";
       }
       else {
          fileroot = mid(fileroot, 0, len(fileroot) - 1);
    	
       }
    }
    Here's the documentation on what mid does

    UDN:
    string Mid ( coerce string S, int i, optional int j )

    The Mid() function generates a substring of S by starting at character i and copying j characters. If j is omitted, the rest of the string is copied. i is clamped between 0 and the length of the string. j is clamped between i and the length of the string. If S is not a string, its value will attempt to be converted to a string value.



    Continuous Delete of 1 Char While BackSpace Key is Down


    You can put my function in a timer loop of say maybe 0.1 seconds so that while backspace is down characters are continuously removed using above code.


    Code:
    exec function BackSpaceDown() {
    	
    	
    	SetTimer(0.1, true, 'backSpaceTimer');
    	
    	
    	keyisdownBackSpace = true;
    	
    }
    exec function BackSpaceUp() {
    	keyisdownBackSpace = false;
    	clearTimer('backSpaceTimer');
    }
    
    function backSpaceTimer() {
    	
    	
    	if (len(fileroot) == 0) return;
    	else if (len(fileroot) == 1) {
    		fileroot = "";
    	}
    	else {
    		fileroot = mid(fileroot, 0, len(fileroot) - 1);
    	}
    	
    }
    UDKGame/Config/DefaultInput.ini (then recompile code using "udk make" or opening UDK)

    Code:
    .Bindings=(Name="GBA_BackSpace",Command="BackSpaceDown | OnRelease BackSpaceUp")
    Binding
    Code:
    .Bindings=(Name="BackSpace",Command="GBA_BackSpace")
    I hope this helps you!



    Rama
Working...
X