Hi,
this is off the top of my head in C#, but it should work. You should be able to
translate it, or someone on here might be able too.
string fn = "my_pic_new2.jpg";
Regex r = new Regex( @"_new(?<count>\d+)" );
Match m = r.Match( fn );
if( ( m != null ) && ( m.Groups[ "count" ].Value.Length >0 ) )
{
string current = m.Groups[ "count" ].Value;
int next = int.Parse( current ) + 1;
fn = fn.Replace( "_new" + current, "_new" + next.ToString() );
}
Cheers!
Dave
----- Original Message -----
From: Tony Trapp
To: [email protected]
Sent: Wednesday, May 11, 2005 4:13 PM
Subject: [AspNetAnyQuestionIsOk] VB.net String maniplulation problem
Hey guys here is what I want to do.
Lets say I have a file name is my database my_pic_new1.jpg first off.
Now I want to change this file name to make it a uniqe file name but
I need to do a few things to the string first.
Is in the string _new is there then I want to see if a number is
there.
If there is a number there I want to take that number and what ever
it is increment that number up by one make the file now
my_pic_new2.jpg
and so on.
I am not asking for someone to write the code for me but point me to
where I can gain viable info on how to make this hapeen or a small
code example.
Here is my code at present,
Dim words1 as String = tmnescort_currentpic_small
Dim location as Integer
Dim Counter as Integer
Dim newstr as Integer
Dim newstring_withnum as Integer
Dim countvar as Integer
Dim newstring_withnum_tostr
dim addnum as String
Counter = 0
location = words1.IndexOf("_new")
If location > 0 or not -1 then
newstring_withnum_tostr = instr(1, words1, "1")
newstr = System.Convert.ToInt16
(newstring_withnum_tostr + 1)
newstring_withnum = newstr & Counter + 1
addnum = System.Convert.ToString(newstring_withnum)
str_msg.Visible = True
str_msg.Text = "This is the pic name in DB " &
tmnescort_currentpic_small & "<br><br>new string was found<br><br>" &
addnum & "<br><br>"
else
str_msg.Visible = True
str_msg.Text = "This is the pic name in DB " &
tmnescort_currentpic_small & "<br>new string was not found<br><br>" &
addnum & "<br><br>"
end if
what I get back printed out is
This is the pic name in DB my_pic_new1.jpg
new string was found
161 << this is what happens after my string manipualtion I dont want
this.
Can any please help me?
Thanks,
Tony...
------------------------------------------------------------------------------
Yahoo! Groups Links
a.. To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
b.. To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
c.. Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
[Non-text portions of this message have been removed]
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/