Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 01-11-2003, 11:23 PM   #1 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,489
sde is on a distinguished road
splitting a string

i'm trying to figure out how to do this in Small, .. but since it is similar to C , then maybe i can find out from how C can do it.

i have a string that contains this:
Code:
apple=fruit
i need to take that string, and break it up into 2 other strings. var_1 and var_2

if it's not obvious, i want apple in var_1 , and fruit in var_2

any ideas?
sde is offline   Reply With Quote
Old 01-12-2003, 06:52 AM   #2 (permalink)
anon
Guest
 
Posts: n/a
for(i=0;i<=5;++i) {
var_1=blah[i];
}

?
  Reply With Quote
Old 01-12-2003, 07:31 AM   #3 (permalink)
DesertWolf
Non-profit Techie
 
DesertWolf's Avatar
 
Join Date: Dec 2002
Location: Mesa AZ
Posts: 76
DesertWolf is on a distinguished road
Send a message via AIM to DesertWolf
First we need to know if your "string" var is really a str variable or a char array pretending to be a string variable.
If it is a true str variable there should be a string fuction to get part of a string from the start of the string for a set number of characters or untill you get to a defined character such as your "=" character, If you are using a char array then I would probably do something similar to what Vlad gave you, looking for the "=" character to give you the end point index number of your first word.
DesertWolf is offline   Reply With Quote
Old 01-13-2003, 10:42 AM   #4 (permalink)
sdeming
Code Monkey
 
Join Date: Jul 2002
Location: Michigan
Posts: 85
sdeming is on a distinguished road
Mike,

In shell it's really quite simple:[SHELL]string=value
OIFS=$IFS
IFS="="
set $string
var1=$1
var2=$2
IFS=$OIFS
echo $var1
echo $var2
[/SHELL]
__________________
Scott
B4 09 BA 09 01 CD 21 CD 20 53 63 6F 74 74 24
sdeming is offline   Reply With Quote
Old 01-13-2003, 10:47 AM   #5 (permalink)
sdeming
Code Monkey
 
Join Date: Jul 2002
Location: Michigan
Posts: 85
sdeming is on a distinguished road
Okay, now I need to RTFM...

I thought you wrote SHELL, not SMALL...

At any rate, in C take a look at strtok(), I'm not sure if it is in Small or not but the gist of it goes like this:
Code:
char *s = "string=value";

char *l1=strtok(s, "=");
char *l2=strtok(NULL, "=");

printf("%s\n%s\n", l1, l2);
__________________
Scott
B4 09 BA 09 01 CD 21 CD 20 53 63 6F 74 74 24
sdeming is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help for another program Androto Standard C, C++ 54 10-15-2004 07:21 AM
sorting objects arrays by object properties sde Java 28 08-05-2004 05:51 AM
From C to Java HighterDK Java 11 07-13-2004 07:15 PM


All times are GMT -8. The time now is 08:42 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting