c#


How to select a next word in a string if string contains true using C#


1. Metadata:
major_brand : qt
minor_version : 512
compatible_brands: qt
encoder : Lavf57.56.101
Duration: 01:49:36.75, start: 0.000000, bitrate: 1069 kb/s
Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 935 kb/s, 24 fps, 24 tbr, 12288 tbn, 48 tbc (default)
Metadata:
handler_name : DataHandler
encoder : Lavc57.64.101 libx264
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default)
Metadata:
In the above string i need only 01:49:36.75, how to get only the next word of "Duration:" in one line of code
Assume s is your string, and these '*' do not exist (I guess you added it):
string sDurationVal = s.Substring(s.IndexOf("Duration") + 9).Split(',')[0].Trim();
Use Substring and IndexOf to remove the first part of the string, such that the new string starts with the desired value.
Split the result by ',' and take the first cell.
Trim it to remove unnecessary spaces.
You should use Regex class to find what you're looking for.
Regex use Regular Expression Language.
Regex rx = new Regex(#"Duration\:\s*([\d\.]+)\,",RegexOptions.Compiled | RegexOptions.IgnoreCase);
Console.WriteLine(rx.Matches("Your String")[0].Groups[0].Value);
For more information you can check here: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx
The Regex is reliable than the other methods like split or IndexOf ...
Make use of .Substring() along with .IndexOf()
string s2 = s.Substring(s.IndexOf("Duration:")+9,12).Trim();

Related Links

Log4Net error : “Failed to find configuration section log4net”
Modelling contact details for a person / customer
MIME pdf for windows 8.1
WCF service contract and error handling
Converting SQL statement to LinQ to SQL query
Generic lists in array list
How to monitor postgresql database table for any changes via c#
how to create a webbroswer in wpf that supports all the sites and scripts and play video?
Code First can't enable migrations
how to compare two gridview and ignore the sequence of data inside
Unity button prefab with different code
Get properties with reflection
LayoutTransform on certain elements in canvas?
ListView wont scroll vertically
Building an RX operator to split one observable of key-value-pairs into multiple observables, one per distinct key
JsonResult interpreted as string by browser

Categories

HOME
qlikview
internet-explorer
msbuild
postgresql-9.3
hiveql
coordinates
mailchimp
symfony-sonata
perl6
css-selectors
clip-path
pip
sitemap
webpack-dev-server
annyang
soap-client
runtime
dynamics-crm-2011
vichuploaderbundle
ldap-query
bookmarklet
smooth-scrolling
sonarlint
smali
symlink
orgchart
launchd
hierarchy
folder
directions
scene7
apache-falcon
matlab-compiler
gitosis
campaign-monitor
azure-storage-files
outlook-2010
instances
delphi-xe
file-descriptor
collation
pexpect
azure-data-catalog
qtwebkit
runner
denodo
intermediate-language
webmatrix
dynatable
magick.net
git-cherry-pick
change-password
usps
cexception
fadein
sqldataadapter
ruby-1.8.7
biginsights
first-order-logic
azure-mobile-app
clearquest
vectordrawable
veeam
numerical-recipes
backtrace
indices
pysvn
javadb
jsonschema2pojo
yosemite
breeze-sharp
tigase
code-smell
image-preloader
.net-reflector
mdp
node-amqp
svg-android
code-complete
scidb
angularjs-select2
kademlia
http-compression
outlook-object-model
nsautoreleasepool
dnsbl
certificate-revocation
jquery-ui-map
github-archive
pinchzoom
datejs
log-shipping
execjs
nbehave
netbeans7.0
nscharacterset
system-analysis
mysql-logic
mdd
retrospectiva
scalable

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile