Computing.Net > Forums > Programming > how to split character in a string

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

how to split character in a string

Reply to Message Icon

Name: impactone
Date: April 22, 2009 at 19:10:30 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

Hi,

I want to write a batch file that can split words within a string. for example, I have a string "Hello-World". I just want to echo out any characters before the "-". so when I echo out, it would just say Hello.

any help would be appreciated.

Thanks in advance



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: April 22, 2009 at 22:06:50 Pacific
Reply:

@echo off & setLocal EnableDelayedExpansion

set str=hello-world

for /f "tokens=1 delims=-" %%a in ("!str!") do (
echo %%a
)


=====================================
If at first you don't succeed, you're about average.

M2


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: how to split character in a string

asp sql - sql query for last char in a string www.computing.net/answers/programming/asp-sql-sql-query-for-last-char-in-a-string/18767.html

Trying to extract characters from a string va www.computing.net/answers/programming/trying-to-extract-characters-from-a-string-va/19040.html

Batch file to count a specific character in a www.computing.net/answers/programming/batch-file-to-count-a-specific-character-in-a/19751.html