• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 150
  • Last Modified:

locate item in a string

hello!

i need a easy and nice way of locating users and theire room

the format is something like this :

user:channel

this si a sample of how i should add them

var
i        : integer;
templist : TStringlist;
temp : string;
temp2 : string;
begin
  templist := TStringlist.Create;
  templist.CommaText := commanicks;

  for i := 0 to templist.Count -1 do
  begin
    temp := templist.Strings[i];
            if pos(temp[1],'@+') <> 0 then
               delete(temp,1,1);

    if frmmain.userlist.Strings.IndexOf(temp) = -1 then
      frmmain.userlist.Strings.Add (temp + '=' + channel);

  end;
  templist.free;

----

someone please help
0
joepezt
Asked:
joepezt
1 Solution
 
mullet_attackCommented:
please, a better example of code, and what exactly is the problem/question?
0
 
CynnaCommented:
joepezt,

I'm not sure if I get you right. If you just need quick way to extract channel
from list of strings with format "username=channel" then copy/paste this:


function UserChannel(list:TStringlist; user:String): String;
var s: String;
    i: Integer;
begin
   i:=list.IndexOf(user+'='); if i=-1 then Exit;
   s:=list.Strings[i];
   Result:=Copy(s, Pos('=',s)+1, Length(s));
end;

// DEMO:
//---------
procedure Tfrmmain.Button1Click(Sender: TObject);
var username: String;
begin
  username:='bla';
  Caption:='User: '+username+' is located in channel: '+UserChannel(frmmain.userlist, username);
end;


If this is not what you want, please be more detailed.
0
 
mullet_attackCommented:
maybe...

function UserChannel(list:TStringlist; user:String): String;
var s: String;
   i: Integer;
begin
  result := list.strings.values[user];

//  i:=list.IndexOf(user+'='); if i=-1 then Exit;
//  s:=list.Strings[i];
//  Result:=Copy(s, Pos('=',s)+1, Length(s));
end;

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
joepeztAuthor Commented:
i temporary solved this by doing:  

    if userlist.IndexOf(temp) = -1 then
    begin
      userlist.Add (temp);
      channellist.Add (channel);
    end;

but i would do nnot want to use 2 stringlists...

the problem is that if this list gets desynked, all channels nmight be out of synch with the userlist..


0
 
mullet_attackCommented:
solved what exactly? I still don't understand what your question is !
0
 
moduloCommented:
Dear expert(s),

A request has been made to close this Q in CS:
http://www3.experts-exchange.com/Community_Support/Q_20607180.html

Without a response in 72 hrs, a moderator will finalize this question by:

 - Saving this Q as a PAQ and refunding the points to the questionner

When you agree or disagree, please add a comment here.

Thank you.

modulo

Community Support Moderator
Experts Exchange
0
 
moduloCommented:
Saving this Q as a PAQ and refunding the 50 points to the questionner

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now