PDA

View Full Version : How to Delete blank spaces from variables


azmanar
08-10-2006, 04:06 PM
Hi,

Anyone has a function to delete blank spaces from an INPUT variable?

Say, a user entered an INPUT EMAIL object with this "hello its me@genome.com" by mistake. When it should be "helloitsme@genome.com".

The objective of deleting the blanks is to launch an email software with the correct email address from an AMS objects such as the Browser Object.

Tek
08-10-2006, 04:12 PM
I think rather than allowing the spaces to be input, since you have control of the input, is to not allow spaces in the first place. Email addresses do not contain spaces so this is the logical approach in my opinion.

Here is a dirty way of doing it. :) Use this in the 'On Key' event screen:


result = Input.GetText("Input1");
if e_Key == 32 then
resulttrimmedright = String.TrimRight(result, nil);
resulttrimmedleft = String.TrimLeft(resulttrimmedright, nil);
Input.SetText("Input1", resulttrimmedleft);
Input.SetSelection("Input1", 1, -1);
end

TJS
08-10-2006, 04:25 PM
I like Tek's solution better but here's another way to do it using the DelimitedStringToTable function from:


Program Files\AutoPlay Media Studio 6.0\Gallery\Scripts


GLOBAL FUNCTIONS

--[[
Function: DelimitedStringToTable
Purpose: Breaks up a string given a delimiter into a table
Arguments: DelimitedString - The string to parse
Delimiter - The delimiter
Returns: A numerically indexed table with the string elements
Example:

string = "Brett,Mark,Darryl,Lorne,Adam";
tbResults = DelimitedStringToTable(string,",");
for i, name in tbResults do
Dialog.Message("Name",name);
end

]]--

function DelimitedStringToTable(DelimitedString, Delimiter)
tbReturn = {};
local strWorking;
local nPos = nil;
local strData;
local nTableIndex = 1;
local nDelimiterLength = String.Length(Delimiter);

if(nDelimiterLength < 1)then
tbReturn[nTableIndex] = DelimitedString;
return tbReturn;
end

strWorking = DelimitedString;
nPos = String.Find(strWorking,Delimiter);
while(nPos ~= -1)do
strData = String.Left(strWorking,nPos-1);
tbReturn[nTableIndex] = strData;
nTableIndex = nTableIndex + 1;
local nLength = String.Length(strWorking);
strWorking = String.Right(strWorking,nLength - (nPos + (nDelimiterLength-1)));
nPos = String.Find(strWorking,Delimiter);
end
if(strWorking ~= "")then
tbReturn[nTableIndex] = strWorking;
end

return tbReturn;
end


ON CLICK

str_Input = Input.GetText("Input1");
str_SpacesRemoved = "";

tbl_Parts = DelimitedStringToTable(str_Input, " ");

for i, v in tbl_Parts do
str_SpacesRemoved = str_SpacesRemoved .. v;
end

Label.SetText("Label1", str_SpacesRemoved);

Intrigued
08-10-2006, 04:35 PM
How about this, it's short and gets the job done:

strOriginal = Input.GetText("Input1")
strNoSpaces = String.Replace(strOriginal, " ", "", false)
Dialog.Message("String without spaces...", strNoSpaces)

TJ_Tigger
08-10-2006, 04:35 PM
I-Man was quick on the draw and beat me to it. D'oh.

Why not use

strEmail = String.Replace(strEmail, " ", "", false);

Replace in the string strEmail all spaces with nothing.

Tigg

Intrigued
08-10-2006, 04:43 PM
heh, heh. Maybe you just let me have that one. (smirk)

Nice job on the Quiz app. Tig'. Looking good there.

azmanar
08-11-2006, 03:43 AM
Hi,

Thanks ye all. Good solutions